#include <stdio.h> #include <fstream> using namespace std; bool FileGetLine(const char* szFileName) { bool fRet = false; int iLineIndex = 0; const int MAX_LINE_LEN = 512; static char szLineData[MAX_LINE_LEN]; ifstream infile; infile.open(szFileName); if ( !infile.fail() ) { while (true) { infile.getline(szLineData, MAX_LINE_LEN); if ( infile.eof() ) { fRet = true; break; } else { printf("%03d:[%s]\n", ++iLineIndex, szLineData); } } infile.close(); } return fRet; } int main(void) { if ( true == FileGetLine("demo.txt") ) { printf("ok\n"); } else { printf("on!\n"); } getchar(); return 0; }