CString csLine;
try
{
CStdioFile file("c://autoexec.bat",CFile::modeRead);
while(file.ReadString(csLine))
AfxMessageBox(csLine);
}
catch(...)
{
AfxMessageBox("打开文件错");
}
参考一段代码:使用ifstream
char* pszPath = NULL;
::GetMacroBasePath(&pszPath);
ifstream file;
file.open(pszPath,ios::nocreate|ios::in);
if(pszPath) delete pszPath;
if(!file.good()) return rtnValue;
char buffer[256];
file.getline(buffer,255);
if(_stricmp(buffer,"VERSION = 1.0") != 0)
return rtnValue;
CString strTemp(_T(""));
file.getline(buffer,255);
while(_stricmp(buffer,"") != 0)
{
strTemp = CString(buffer);
。。。
file.getline(buffer,255);
}
CStdioFile f;
CFileException e;
char *FileName = "temp.txt";
if( !f.Open( FileName, CFile::modeRead, &e ) )
{ return;}
CString line;
while (f.ReadString(line))
{
}
f.Close();
char szT[256];
memset( szT, 0, 256 );
fp = fopen( "test.txt", "r" );
fscanf( fp, "%s", szT );
strcpy( szcc, szT );
while( !feof(
vc读取文本文件
最新推荐文章于 2023-06-11 23:29:36 发布