导航

VC按行读取文本

Posted on 2008-12-24 08:42  Mike Huang  阅读(718)  评论(0)    收藏  举报

CStdioFile File;  //文本文件操作一般用这个类
CString File_Path;
char szPath[MAX_PATH];  //数组
GetCurrentDirectory(MAX_PATH, szPath);// MAX_PATH 预定义的常量=256

CString FileData;
strcat(szPath,"\\Debug\\");
strcat(szPath,"1.txt");// strcat 追加字符串.szPath是char * 所以不能szpath+="str";
AfxMessageBox(szPath);
File.Open(szPath,CFile::modeRead); // TODO: Add extra validation here

while (File.ReadString(FileData))

{
AfxMessageBox(FileData);
}