0

我只是想将一些文本数据写入制表符分隔的文件。这是代码。Name() 和 File() 返回 CStringW,而 ID() 返回 int,

ofstream myfile(file);

if (myfile.is_open())
{
    v::iterator i = begin();

    while(i != end())
    {
        myfile << i->Name() << L"\t" << i-ID() << L"\t" << i->File() << endl;
       i++;
    }

    myfile.close();

 }

但不是得到我期望的输出,文件看起来像这样

001554B00043F66840043F668001554F8
001555400043F6685440043F66800155588
001555F00043F6686000043F66800155638
001556B00043F6686240043F668001556F8
001557700043F6686680043F668001557B8
001558300043F6686800043F66800155878
001558E00043F6688560043F66800155928
001559C00043F6688720043F66800155A08
00155A700043F6689480043F66800155AB8
00155B200043F66810440043F66800155B68
00155BD00043F66811320043F66800155C18
00155C800043F66812840043F66800155CC8
00155D300043F66814040043F66800155D78
00155DE00043F66815360043F66800155E28
00155E900043F66815840043F66800155ED8
00155F400043F66816880043F66800155F88
001560180043F66817040043F66800156050
001560C80043F66817360043F66800156110

是什么赋予了?

4

2 回答 2

3

使用wofstream具有适当运算符的a const wchar_t *

wchar_t *toostream将使用operator<<(ostream &, void *),因为没有运算符 forwchar_t *

编辑:在 CStringW 上使用 .GetString()。

于 2011-02-16T17:50:35.650 回答
1

我通常看到的处理方式是将 CStringW 转换为 LPCWSTR,如下所示:

myfile << (LPCWSTR)i->Name() << L"\t" << i-ID() << L"\t" << (LPCWSTR)i->File() << endl;
于 2011-02-16T20:48:12.060 回答