cfile

Getsavefilename()样例代码片段

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 06:04:02
Getsavefilename()样例代码片段 OPENFILENAME ofn ; TCHAR szFile[MAX_PATH] ; ZeroMemory(&ofn,sizeof(ofn)) ; ofn .lStructSize = sizeof(ofn) ; ofn .hwndOwner = m_hWnd ; ofn .lpstrFile = szFile ; ofn .lpstrFile [ 0 ] = _T( '\0' ) ; ofn .nMaxFile = sizeof(szFile) ; ofn .lpstrFilter = _T( "Text\0*.txt\0" ) ; ofn .nFilterIndex = 1 ; ofn .lpstrFileTitle = NULL ; ofn .nMaxFileTitle = 0 ; ofn .Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT ; CString strFile ; if (GetSaveFileName(&ofn)) { strFile .Format (_T( "%s" ),szFile) ; } else return ; if (strFile .Find (_T( '.' ))!= - 1 ) { strFile = strFile .Left (strFile

UTF-8, CString and CFile? (C++, MFC)

故事扮演 提交于 2019-11-27 00:31:20
问题 I'm currently working on a MFC program that specifically has to work with UTF-8. At some point, I have to write UTF-8 data into a file; to do that, I'm using CFiles and CStrings. When I get to write utf-8 (russian characters, to be more precise) data into a file, the output looks like Ðàñïå÷àòàíî: Ñèñòåìà Ïðîèçâîäñòâî and etc. This is assurely not utf-8. To read this data properly, I have to change my system settings; changing non ASCII characters to a russian encoding table does work, but

文件操作

大兔子大兔子 提交于 2019-11-26 19:42:56
1、C文件操作 2、c++文件操作 3、MFC文件操作: CFile是MFC的文件操作基本类,它直接支持无缓冲的二进制磁盘I/O操作,并通过其派生类支持文本文件、内存文件和socket文件。 Visual C++处理的文件通常分为两种: 文本文件:只可被任意文本编辑器读取ASCII文本。 二进制文件:指对包含任意格式或无格式数据的文件的统称。 1、定义文件变量 定义文件变量格式:CStdioFile 文件变量; 例如,定义一个名称为f1的文件变量,语句如下:CStdioFile f1; 2、打开指定文件 可以直接通过CStdioFile的构造函数来打开磁盘文件,同时可以用标志位指定打开方式(只读、只写、读写等): CStdioFile(LPCTSTR lpszFileName,UINT nOpenFlags); 实例1:以只读方式打开一个文件 步骤: 使用AppWizard创建一个对话框应用程序,删除其自动产生的所有控件,添加一个Button控件。双击控件,在相应的函数里添加代码: char * pszFileName="C://myfile.txt"; CStdioFile myFile; CFileException fileException; if(!myFile.Open(pszFileName,CFile::modeCreate|CFile::typeText

MFC常用类

流过昼夜 提交于 2019-11-26 14:57:45
CString CStringT 操作可变长度字符串的模板类CStringT有三个实例: CString、CStringA和CStringW ,它们分别提供对TCHAR、char和wchar_t字符类型的字符串的操作。 char类型定义的是Ansi字符,wchar_t类型定义的是Unicode字符,而TCHAR取决于MFC工程的属性对话框中的Configuration Properties->General->Character Set属性,如果此属性为Use Multi-Byte Character Set,则TCHAR类型定义的是Ansi字符,而如果为Use Unicode Character Set,则TCHAR类型定义的是Unicode字符。 构造函数 CString(const CString& stringSrc);//将一个已经存在的CString对象stringSrc的内容拷贝到该CString对象。 CString(LPCTSTR lpch, int nLength);//将字符串lpch中的前nLength个字符拷贝到该CString对象。 CString(TCHAR ch, int nLength = 1);//使用此函数构造的CString对象中将含有nLength个重复的ch字符。 转换函数 CString& MakeLower(); /