首页 > 编程 > C++ > 正文

C++文件操作小记

2019-11-06 07:06:00
字体:
来源:转载
供稿:网友
int main(int argc, const char * argv[]) { ofstream testfile_1("test.txt"); if (testfile_1.is_open()) {// testfile_1<<"This is a line."<<endl;// testfile_1<<"This is another line"<<endl; cout<<"input the polynome"<<endl; string s ; getline(cin,s); testfile_1<<s<<endl; testfile_1.close(); } string buffer; ifstream testfile_2("test.txt"); if (!testfile_2.is_open()) { cout<<"Error opening file"<<endl; exit(1); } while (!testfile_2.eof()) { getline(testfile_2,buffer); cout<<buffer<<endl; } return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选