Aan
Aan

Reputation: 12890

Outputting 'wchar_t*' to an 'ofstream'

I want to output a text to a file via two pointers that I have declared:

wchar_t   *Col1="dsffsd", *Col2="sdfsf";

Here is what I have tried:

std::ofstream fout;
fout.open(NativeDatabasePathHist);
fout<<"testing";
fout<<" "<<Col1<<" "<<Col2;
fout.close();

And here is what I am getting:

testing 113 113

Why is it that when I print Col1 and Col2, I am getting numbers instead of strings?

Upvotes: 19

Views: 23394

Answers (2)

Dmitriy
Dmitriy

Reputation: 5487

First, use std::wofstream instead of std::ofstream.

Also, use the L prefix on your text string to indicate that your text is wide character text:

wchar_t   *Col1=L"dsffsd"

Upvotes: 23

wallyk
wallyk

Reputation: 57764

Since you have written it using wide characters (wchar_t), you need to look at the resulting file with something that understands wide characters.

Upvotes: 0

Related Questions