Cfile关于打开文件的操作

来源:互联网 发布:webgl编程指南 pdf 编辑:程序博客网 时间:2024/05/16 11:50

1.简单的从Char到我们Cfile中需要的类型

#include <iostream>#include <afx.h>using namespace std ;int main(){//写CFile cfile;const char* msg="ab.txt"; wchar_t *wmsg = new wchar_t[strlen(msg)+1]; //memory allocationmbstowcs(wmsg, msg, strlen(msg)+1);cfile.Open(wmsg, CFile::modeCreate | CFile::modeReadWrite);char pbufWrite[100];memset(pbufWrite, 'a', sizeof(pbufWrite));cfile.Write(pbufWrite, 100);         cfile.Flush();delete []wmsg;system("pause");}
2.不用char类型,直接用_T类型的方法

#include <iostream>#include <afx.h>using namespace std ;int main(){CFile cfile;TCHAR* pszFileName = _T("f.txt");cfile.Open(pszFileName, CFile::modeCreate | CFile::modeReadWrite);char pbufWrite[100];memset(pbufWrite, 'a', sizeof(pbufWrite));cfile.Write(pbufWrite, 100);         cfile.Flush();system("pause");}



0 0
原创粉丝点击