C++文件读写,写文件两个回车结束

#include <iostream>
#include <fstream>
#include<stdlib.h>
#include <string>//not <string.h>

using namespace std;

int main()
{
ifstream in_stream;//read file
ofstream out_stream;//write file

string quit = " ";
while(quit != "quit")
{
//output the advice that arised by the last person
in_stream.open("D:\\代码和工程\\Visual Studio 2010\\Projects\\homework5_5\\advice.txt");

if(!in_stream)
{
cout << "Can not open the file!"<<endl;
abort();//exit the program <stdlib.h>
}

char str[80];
cout << "The advice is " << endl;
while(!in_stream.eof())
{
in_stream.getline(str,sizeof(str));

cout << str << endl ;
}

in_stream.close();

//input the new person's advice and record it
cout << "Please enter your advice by pressing Enter key twice." << endl;
out_stream.open("D:\\代码和工程\\Visual Studio 2010\\Projects\\homework5_5\\advice.txt");
if(!out_stream)
{
cout << "Can not open the file!"<<endl;
abort();//exit the program <stdlib.h>
}

char c, last = ' ';
while(1)
{
c = cin.get();
if (c == 10 && last == 10)
{
break;
}
last = c;
out_stream << c;
}

out_stream.close();
cout << "Please press any key to continue.Press 'quit' to quit";
cin >> quit;
cout << endl;
}


system("pause");
return 0;
}

原文地址:https://www.cnblogs.com/syxxlove/p/2800622.html