使用I/O流以文本方式打开上题建立的文件test1.txt,在次此文件后面添加字符“已成功添加字符!”,然后读出整个文件的内容显示出来,看看是否正确。
1 #include <iostream> 2 #include <string> 3 #include<string.h> 4 #include <fstream> 5 using namespace std; 6 7 8 int main(){ 9 char ch; 10 ofstream file1("text1.txt", ios::app); 11 file1<<"已成功添加字符!"; 12 file1.close(); 13 ifstream file2("text1.txt"); 14 while(file2.get(ch)) cout<<ch; 15 file2.close(); 16 return 0; 17 }
标签:11,字符,file1,include,文件,txt From: https://www.cnblogs.com/YUZE2001/p/17266361.html