ios::in:
打开输入文件,可防止文件内容删除,但是输入内容时从文件第一个位置开始并且会覆盖后面的内容
ios::ate:
如果没有文件,生成空文件;
如果有文件,清空该文件
ios::app:
如果没有文件,生成空文件;
如果有文件,在文件尾追加
ios::trunc打开某个文件时,如果没有上述三个中任意一个指定,就会默认为该模式,会删除打开文件的内容(指已存在的文件)
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
// cout.put('a');
int a[10] = { 1,2,3,4};
string str,str1 ;
cin >> str;
ofstream file("test.txt", ios::out|ios_base::app);
file << str;
file.close();
ifstream ifile("test.txt", ios::in);
ifile >> str1;
cout << str1<<endl;
return 0;
}