C中读取一行一行的读取文件

来源:互联网 发布:2选一数据选择器vhdl 编辑:程序博客网 时间:2024/05/11 19:45

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);        }    }}