如何从文本文件中逐行读取?

fenddy0001 2003-02-19 04:46:43
我用ATL作的组件中,需要从文本文件中逐行读取字符串,请问
有没有简单的函数或方法可以直接使用? 文件很大,所以...
请各位老大帮帮忙!!!
...全文
215 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fenddy0001 2003-02-25
  • 打赏
  • 举报
回复
问题解决了,还是用MFC.
DoubleJiang 2003-02-19
  • 打赏
  • 举报
回复
up
fenddy0001 2003-02-19
  • 打赏
  • 举报
回复
对不起,可能我没写清楚。文本文件中的行数、字符数是不定的。而且,不可以保存。
fenddy0001 2003-02-19
  • 打赏
  • 举报
回复
各位老大,咱不用MFC的可以吗?
loopyifly 2003-02-19
  • 打赏
  • 举报
回复
CStdioFile f;
f.ReadString();
LinHanLao 2003-02-19
  • 打赏
  • 举报
回复
CString LineText;
CStdioFile stFile;
BOOL ret = TRUE;
int Num = 0;
int iPos = -1;
CString ch;

stFile.Open(FilePathName, CFile::modeRead | CFile::typeText);

while(1)
{
ret = stFile.ReadString(LineText);
if(!ret)
{
break;
}

LineText.LeftTrim();
LineText.RightTrim();
while(1)
{
iPos = LineText.Find(",");
if(iPos == -1)
{
Num = atoi(ch.GetBuffer(10)); //想办法保存Num
break;
}
ch = LineText.Left(iPos);
Num = atoi(ch.GetBuffer(10)); //想办法保存Num
LineText.Delete(iPos + 1);
LineText.LeftTrim();
}
}
stFile.Close();

librastar2001 2003-02-19
  • 打赏
  • 举报
回复
void InfoRecord(CString Description)
{
CStdioFile aFile;
CFileException fx;
char DirectoryC[100];
CString Stringtemp;
GetModuleFileName(NULL,DirectoryC,100);
Stringtemp.Insert(0,DirectoryC);
Stringtemp.Delete(Stringtemp.Find("\\AGManager.exe",0),14);
Stringtemp=Stringtemp+"\\InfoRecord.txt";

if( !aFile.Open( Stringtemp, CFile::modeWrite | CFile::typeText, &fx ) )
{
TCHAR buf[ 255 ];
fx.GetErrorMessage( buf, 255 );
CString strPrompt( buf );
AfxMessageBox( strPrompt );
return;
}
aFile.SeekToEnd();
CTime CT=CTime::GetCurrentTime();
Description=Description+" "+CT.Format("%H:%M:%S,%A,%B %d,%Y")+"\n";
aFile.WriteString(Description);
aFile.Close();
}
masterz 2003-02-19
  • 打赏
  • 举报
回复
CStdioFile::ReadString
virtual LPTSTR ReadString( LPTSTR lpsz, UINT nMax );
throw( CFileException );

BOOL ReadString(CString& rString);
throw( CFileException );

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧