c++ - 如何使用 Unicode 中的 CFile::Read() 从文件中获取 CString 对象?

标签 c++ unicode cstring cfile

字符集是 Unicode。我想将一个CString类型的字符串写入一个文件,然后再从文件中读出。 我使用 CFile::Write() 方法将字符串写入文件:

int nLen = strSample.GetLength()*sizeof(TCHAR);
file.Write(strSample.GetBuffer(), nLen);

问题是:我想从包含strSample内容的文件中获取CString。我该怎么做?

非常感谢!

最佳答案

UINT nBytes = (UINT)file.GetLength();
int nChars = nBytes / sizeof(TCHAR);
nBytes = file.Read(strSample.GetBuffer(nChars), nBytes);
strSample.ReleaseBuffer(nChars);

关于c++ - 如何使用 Unicode 中的 CFile::Read() 从文件中获取 CString 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1483068/

相关文章:

string - 用C样式的字符串调用C函数

c++ - 在 C 中打印 unicode 文字

json - 在 Go JSON 中转义 unicode 字符,以便输出与 Python 匹配

ASP.NET:将 XmlDocument 保存到 Response.OutputStream 会遵守编码吗?

C 字符串指针函数 strdel

c - 如何找到 strtok() 拆分字符串的索引?

c++ - 使用 Boost.Python 设置包装类的元类

c++ - PRId16 扩展到 d

c++ - 如何在 C++ 中的文件列表中逐个文件打开文件?

c++ - 如何使用成员方法作为回调而不是像设计这样的状态机的静态方法