Printing a C ++ LPCWSTR file to a file

I am trying to print the LPCWSTR value for a file, but it prints only the address, not the value.

I tried dereferencing a variable (using *) to get the value, but this also does not work.

How to print the value?

void dump(LPCWSTR text){

  ofstream myfile("C:\\myfile.txt", ios::app );
  myfile << text << endl;
  myfile.close();

}

Thanks in advance.

+3
source share
2 answers

Use wofstream(basic_ofstream). The reason for this will be that the versions of std streams ware designed to work with wide character strings and data. The narrow version you are using will see a wide line, which probably contains some inline zeros and will think that this is the end of the line.

+2
source

wofstream , unicode ( ). , , .

, , 8- , ++ Unicode 8- .

wcstombs 8- . , , setlocale, , . , setlocale , UTF-8: (

+1

Source: https://habr.com/ru/post/1705902/


All Articles