向文本文件中写入内容

来源:互联网 发布:java线程池种类 编辑:程序博客网 时间:2024/05/16 18:22
#include <fstream>#include <iostream>#include <string>using namespace std;int main(){// ofstream is used for writing files// We'll make a file called Sample.txtofstream outf("Sample.txt");//注意:此处的等价于:ofstream outf;outf.open("Sample.txt");// If we couldn't open the output file stream for writingif (!outf){// Print an error and exitcerr << "Uh oh, Sample.dat could not be opened for writing!" << endl;exit(1);}// We'll write several lines into this filestring s;getline(cin,s);while(s.size()){outf<<s<<endl;//将s写入文本文件getline(cin,s);}return 0;}

原创粉丝点击