CStdioFile file;
CString strLine,strtemp;
if(!file.Open( "d:\\test.txt ",CFile::modeRead))return;//打开*.TXT这个文件,打开形式为读取
int row = 0; //定义行变量
while(file.ReadString(strLine))
{
char *str = strLine.GetBufferSetLength(strLine.GetLength());
char *p;
if(strLine!="")
{
for (p=strtok(str," ");p!=NULL;p=strtok(NULL," "))
{
}
MessageBox(strtemp);
}
}
file.Close();
本文介绍了如何使用MFC的CStdioFile类按行读取txt文件,并通过strtok函数分割每行数据。示例代码演示了打开txt文件,逐行读取,然后利用空格作为分隔符将每行内容拆分成单独的字符串。
1323

被折叠的 条评论
为什么被折叠?



