您的位置:首页 > 编程语言 > C语言/C++

Sample of C++ read/write a text file

2009-06-05 17:16 399 查看
#include <iostream>

#include <fstream>

using namespace std;

int main()

{

const char *filename = "t.txt";

ofstream ofile;

ifstream ifile;

//write

ofile.open(filename);

ofile << "111111111111" << endl;

ofile << "222222222222" << endl;

ofile.close();

//read

string str;

ifile.open(filename);

while(ifile >> str)

cout << str << endl;

ifile.close();

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: