10

我是 c++ 的一种新手,同时在 windows CE .net compact 应用程序上工作

在尝试将六进制数据写入文件时

CString dataBlock1;
dataBlock1 = "";

CString temp;
for(int i = 0; i < rLen; i++)
{
temp.Format(L"%02X ",rec[i]);
dataBlock1 += temp;

}

std::ofstream out(file);

在使用以下写入函数将六进制数据写入文件时,我收到此错误无法将参数 1 从 wchar * 转换为 const char*

out.write(myReader.dataBlock1.GetBuffer(),myReader.dataBlock1.GetLength());

我们如何将 wchar_* 转换为 const char* 以使 write 函数工作。

谢谢。

4

2 回答 2

7

您可以使用该wcstombs功能,请参考此处

于 2011-11-11T19:10:39.090 回答
1

Windows 有一组类和函数,它们采用 wchar_t(存储为 UTF-16 的文本)和 char(存储在 ANSI 字符集中的文本)。如果您有指向 wchar_t 的指针,则需要使用接受 wchar_t 的适当类或函数,或者需要将数据转换为 ANSI 字符集。

在这种情况下,您需要 ofstream 的 wchar_t 变体 wofstream。

于 2011-11-11T18:57:33.453 回答