65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream fs("test.txt");
cout<<fs.rdbuf()<<endl;//1.显示文件内容到控制台;
string line;
do
{
while(getline(cin,line))
fs<<line;
cout<<"是否继续:";//请问这句话什么时候输出?按ctrl+z的话会不断的输出这句话
char choice;
cin>>choice;
if(choice=='n')
break;
}while(true);
return 0;
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream fs("test.txt");
if (!fs.is_open())return 1;
cout<<fs.rdbuf();//1.显示文件内容到控制台;
string line;
do
{
while(getline(cin,line))
fs<<line;
cout<<"是否继续:";
char choice;
cin>>choice;
if(choice=='n')
break;
}while(true);
return 0;
}……
1.显示文件内容到控制台;
2.从控制台输入任何内容追加到文件末尾;
3.询问是否继续追加内容
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream fs("test.txt");
cout<<fs.rdbuf();//1.显示文件内容到控制台;
string line;
do
{
while(getline(cin,line))
fs<<line;
cout<<"是否继续:";
char choice;
cin>>choice;
if(choice=='n')
break;
}while(true)
return 0;
}……
1.显示文件内容到控制台;
2.从控制台输入任何内容追加到文件末尾;
3.询问是否继续追加内容
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream fs("test.txt");
cout<<fs.rdbuf();//1.显示文件内容到控制台;
string line;
do
{
while(getline(cin,line))
fs<<line;
cout<<"是否继续:";
char choice;
cin>>choice;
if(choice=='n')
break;
}while(true)
return 0;
}