Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 531
Aan Avatar asked Oct 15 '12 04:10

Aan


People also ask

How do I print a wide character in C++?

We can see that to make wide character we have to add 'L' before the character literal. But the character value is not displayed in the output using cout. So to use wide char we have to use wcout, and for taking input we have to use wcin. We can make some wide character array, and print them as string.

What is wfstream?

std::wfstreamA set of internal flags that affect how certain input/output operations are interpreted or generated.


1 Answers

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"
like image 171
Dmitriy Avatar answered Oct 20 '22 00:10

Dmitriy