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读取文本文件
最新推荐文章于 2024-09-07 10:11:26 发布
本文介绍了在VC中处理文本文件的方法,包括使用CStdioFile和CFile类的读写操作,强调了CFile的Read和Write函数,并提醒注意行结束符和文件定位。示例代码展示了如何读取文件、更新行内容并写回文件。
摘要由CSDN通过智能技术生成