字符集是 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/