fstream

fstream file("b.txt", ios::in|ios::out|ios::app);

mode

  • ate - seek to the end of stream immediately after open,不会导致create属性
  • app - seek to the end of stream before each write,Every output is appended at the end of file, 可造成out属性
  • in 表示只读属性
  • out 表可写属性+create属性
  • in+out 表只读+可写属性(没有create属性)
  • trunc

class default mode to parameter
ofstream ios::out | ios::trunc
ifstream ios::in
fstream ios::in | ios::out

//fstream file("b1.txt", fstream::in|fstream::out); do NOT create if no exist
fstream file("b1.txt", fstream::out);   // create
file<<"s";
cout<<"s";
file.close();
}
上一篇:C#断点续传的实现


下一篇:C++ IO库 文件流详解 iostream fstream