其他分享
首页 > 其他分享> > MFC文件操作

MFC文件操作

作者:互联网

嘴硬到底是什么概念,大概就是,你问我是怎么想的,其实我眼泪都要掉下来了,但我还是说了句,算了,就这样吧。。。

----  网易云热评

一、创建windows桌面向导

设为启动项、修改静态MFC、多字节

 

二、创建和打开文件

void File() {       CFile file;       //modeCreate:没有就创建,有直接打开       //modereadwrite:读写方式打开       file.Open("E:/a.txt",CFile::modeCreate|CFile::modeReadWrite);       file.Write("aiyoubucuo", strlen("aiyoubucuo"));       file.SeekToBegin();       char buf[256] = { 0 };       file.Read(buf, 256);       printf("%s\n", buf);       file.Close();}

 

三、遍历文件

void Find(CString path) {       CFileFind find;       BOOL goFind = find.FindFile(path + "/*.*");       while (goFind) {              goFind = find.FindNextFile();              CString filename = find.GetFileName();              CString filepath = find.GetFilePath();                //不能是空目录且不能是. ..目录              if (find.IsDirectory() && !find.IsDots()) {                     printf("[%s]\n", filename);                     Find(filepath);              }              else {                     printf("%s\n", filename);              }       }       find.Close();}

 

欢迎关注公众号:顺便编点程

 

标签:CFile,文件,MFC,filename,file,printf,操作,buf,find
来源: https://blog.csdn.net/weixin_41489908/article/details/111978315