C++中:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string s;
ifstream fp("test.txt");
if (!fp)
{
cerr << "OPEN ERROR" << endl;
return 1;
}
while (getline(fp,s))
{
cout << s << endl;
}
fp.close();
return 0;
}
MFC中:
#include <afx.h>
#include <stdio.h>
void main()
{
CString buff;
CStdioFile cFile;
BOOL bOpen = cFile.Open("1.txt", CFile::modeRead);
if(bOpen)
{
while(cFile.ReadString(buff))
{
printf("%s\n", buff);
}
}
}