如何在C ++中将文本追加到文本文件?
这是将文本追加到文本文件的C++程序。
算法
Begin
Open that file a1.txt as output file stream class object to perform
output operation in append mode using fout file reference.
If the file exists then
Appending text to that file.
Close fout.
Open the file “a1.txt” for reading the content of the file.
Extracting the text from file and printing the text.
End.范例程式码
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main() {
fstream f;
ofstream fout;
ifstream fin;
fin.open("a1.txt");
fout.open ("a1.txt",ios::app);
if(fin.is_open())
fout<<" nhooo.com";
cout<<"\n Data has been appended to file"<<endl;
fin.close();
fout.close();
string word;
f.open("a1.txt");
while (f >> word) {
cout << word << " ";
}
return 0;
}输出结果
Data has been appended to file
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短