Rob*_*bin 10 c++ fstream ofstream
有什么区别:
fstream texfile;
textfile.open("Test.txt");
Run Code Online (Sandbox Code Playgroud)
和
ofstream textfile;
textfile.open("Test.txt");
Run Code Online (Sandbox Code Playgroud)
他们的功能是一样的吗?
ofstream只有输出方法,所以例如,如果你尝试textfile >> whatever它不会编译.fstream可以用于输入和输出,虽然将起作用取决于您传递给构造函数/的标志open.
std::string s;
std::ofstream ostream("file");
std::fstream stream("file", stream.out);
ostream >> s; // compiler error
stream >> s; // no compiler error, but operation will fail.
Run Code Online (Sandbox Code Playgroud)
评论有一些更好的观点.
| 归档时间: |
|
| 查看次数: |
20737 次 |
| 最近记录: |