使用CFile::typeUnicode
我需要能够读/写包含汉字的unicode字符串的文件 文档中说CFile::typeUnicode“仅在派生类中使用”,但我找不到任何使用它的派生类的引用 有没有允许我读写unicode的“官方”版本的CFile使用CFile::typeUnicode,unicode,mfc,Unicode,Mfc,我需要能够读/写包含汉字的unicode字符串的文件 文档中说CFile::typeUnicode“仅在派生类中使用”,但我找不到任何使用它的派生类的引用 有没有允许我读写unicode的“官方”版本的CFile 或者我最好尝试使用这样的方法:这似乎是一种更简单的方法:看,它使用文件流以Unicode格式打开一个文件,然后使用该流打开一个CStdioFile类 // // For Writing // // Old-Style... do not use... //CStdioFile f;
或者我最好尝试使用这样的方法:这似乎是一种更简单的方法:看,它使用
文件
流以Unicode格式打开一个文件,然后使用该流打开一个CStdioFile
类
//
// For Writing
//
// Old-Style... do not use...
//CStdioFile f;
//f.Open(_T("\test.txt"), CFile::modeCreate | CFile::modeWrite);
// Open the file with the specified encoding
FILE *fStream;
errno_t e = _tfopen_s(&fStream, _T("\test.txt"), _T("wt,ccs=UNICODE"));
if (e != 0) return; // failed..
CStdioFile f(fStream); // open the file from this stream
f.WriteString(_T("Test"));
f.Close();
//
// For Reading
//
// Open the file with the specified encoding
FILE *fStream;
errno_t e = _tfopen_s(&fStream, _T("\test.txt"), _T("rt,ccs=UNICODE"));
if (e != 0) return; // failed..CString sRead;
CStdioFile f(fStream); // open the file from this stream
CString sRead;
f.ReadString(sRead);
f.Close();
这似乎是一种更简单的方法:它使用
文件
流以Unicode格式打开一个文件,然后使用该流打开一个CStdioFile
类
//
// For Writing
//
// Old-Style... do not use...
//CStdioFile f;
//f.Open(_T("\test.txt"), CFile::modeCreate | CFile::modeWrite);
// Open the file with the specified encoding
FILE *fStream;
errno_t e = _tfopen_s(&fStream, _T("\test.txt"), _T("wt,ccs=UNICODE"));
if (e != 0) return; // failed..
CStdioFile f(fStream); // open the file from this stream
f.WriteString(_T("Test"));
f.Close();
//
// For Reading
//
// Open the file with the specified encoding
FILE *fStream;
errno_t e = _tfopen_s(&fStream, _T("\test.txt"), _T("rt,ccs=UNICODE"));
if (e != 0) return; // failed..CString sRead;
CStdioFile f(fStream); // open the file from this stream
CString sRead;
f.ReadString(sRead);
f.Close();
<>你也可以考虑使用一个不同的类来完成你所有的辛勤工作。我使用CTextFileDocument: 您可以使用提供的CTextFileWrite写入多种Unicode格式。例如:
//Create file. Use UTF-8 to encode the file
CTextFileWrite myfile(_T("samplefile.txt"),
CTextFileWrite::UTF_8 );
ASSERT(myfile.IsOpen());
//Write some text
myfile << "Using 8 bit characters as input";
myfile.WriteEndl();
myfile << L"Using 16-bit characters. The following character is alfa: \x03b1";
myfile.WriteEndl();
CString temp = _T("Using CString.");
myfile << temp;
//创建文件。使用UTF-8对文件进行编码
CTextFileWrite myfile(_T(“samplefile.txt”),
CTextFileWrite::UTF_8);
断言(myfile.IsOpen());
//写一些文字
MyFrase你也可以考虑使用一个不同的类来完成所有的辛苦工作。我使用CTextFileDocument:
您可以使用提供的CTextFileWrite写入许多Unicode风格。例如:
//Create file. Use UTF-8 to encode the file
CTextFileWrite myfile(_T("samplefile.txt"),
CTextFileWrite::UTF_8 );
ASSERT(myfile.IsOpen());
//Write some text
myfile << "Using 8 bit characters as input";
myfile.WriteEndl();
myfile << L"Using 16-bit characters. The following character is alfa: \x03b1";
myfile.WriteEndl();
CString temp = _T("Using CString.");
myfile << temp;
//创建文件。使用UTF-8对文件进行编码
CTextFileWrite myfile(_T(“samplefile.txt”),
CTextFileWrite::UTF_8);
断言(myfile.IsOpen());
//写一些文字
我的文件