当前位置:   article > 正文

文件打开模式ios::in|ios::out|ios::trunc

ios::out
  1. //不知道是因为内存的缓存吧,文件流这边的响应总是不太及时
  2. 预测,如果是这种方式打开,应该是先清除内容再打开文件
  3. //实际结果,ios::out并不会在文件打开前把文件内容都清除
  4. #include<cstdio>
  5. #include<iostream>
  6. #include<fstream>
  7. using namespace std;
  8. int main(){
  9. fstream fs2("L7_F0_P1.txt",ios::in|ios::out);
  10. if(!fs2){
  11. cout<<"Error opening file\n";
  12. return 1;
  13. }
  14. int number=0;//放进来的应该是0啊
  15. // fs2>>number;
  16. // cout<<number<<endl;
  17. while(fs2>>number){
  18. cout<<number<<endl;
  19. }
  20. fs2.close();
  21. return 0;
  22. }


Q(c):Modify L7_F0_P1.txt such that it looks as follows 463 859A203 20 (replace space between 859 and
203 with letter A). What is the output of our program and why?

A(c):There will be the two numbers in the output, i.e., 463 and 859. Then the next attempt to read from
ifs results in ifs >> number evaluated to false and end of the while loop

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/300428
推荐阅读
相关标签
  

闽ICP备14008679号