1 文件写
#include<fstream>
using namespace std;
int main()
{
ofstream out("w.txt");
if(out.is_open())
{
out << "this is a line" << endl;
out << "this is anthor line";
out.close();
}
return 0;
}
2 文件读 #include<iostream> #include<fstream> using namespace std; int main() { char buff[256]; ifstream in("w.txt"); while(!in.eof()) { in.getline(buff, 100); cout << buff << endl; } return 0; }
原文:http://www.cnblogs.com/i80386/p/4356238.html