1.写文本文件
#include <fstream>
int main ()
{ofstream test ("c:\\Test.txt");
if (test.is_open())
{ test << "This is a line.\n";
test << "This is another line.\n";
test.close();
}
return 0;
}
2.读上面写的文本文件
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{ char buffer[256];
ifstream test ("c:\\Test.txt");
if (test.is_open())
{while (!test.eof() )
{test.getline (buffer,100);
cout << buffer << endl;
}
test.close();
}
system("pause");
return 0;
}