1.文件写入(会覆盖原先的文件,相当于把原本的文件删了)
#include<bits/stdc++.h>
using namespace std;
int main()
{
fstream f;
f.open("d://file_name.txt",ios::out);
f.close();
}
2.追加写入,不会覆盖原本的文件
#include<bits/stdc++.h>
using namespace std;
int main()
{
fstream f;
f.open("d://file_name.txt",ios::out|ios::app);
f.close();
}
3.内容的读取
#include<bits/stdc++.h>
using namespace std;
int main()
{
fstream f;
// f.open("d://file_name.txt",ios::out|ios::app);
// f.close();
f.open("d://dasabi.txt",ios::in);
string s;
while(f >> s)
cout << s << " ";
f.close();
}