打开文件时如果文件不存在,则创建,那么对于fstream,ifstream,ofstream,怎样设置文件模式
打开文件时如果文件不存在,则创建,那么对于fstream,ifstream,ofstream
其文件模式应该是什么?
我试验了一下,如下能在文件不存在时创建
ifstream file;
file.open(("t.txt",ifstream::out/*|fstream::in*/|ifstream::app);
或file.open(("t.txt",ifstream::out/*|fstream::in*/|ifstream::trunc);
fstream file1;
file1.open("tt.txt",fstream::out/*|fstream::in|fstream::trunc*/);
ofstream file2;
file2.open("y.txt"/*,ofstream::out|fstream::in|ofstream::trunc*/);
(1)打开文件时如果文件不存在,则创建,那么对于fstream,ifstream,ofstream,
其文件模式应该怎样设置(我如上的模式设置有没有错)?
(2)为什么ifstream只使用ifstream::out,不会自动创建文件?
(3) 还有像
fstream file1;
file1.open("tt.txt",fstream::out);
这里是不是不一定使用fstream::out,也可使用ifstream::out 或ofstream::out?
fstream::out,ifstream::out ,ofstream::out 是不是对应同一个常数?