How to convert Wchar_t * to const char *

I’m kind of new to C ++, working on a compact Windows CE.net application

when trying to write hexadecimal data to a file

CString dataBlock1;
dataBlock1 = "";

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

}

std::ofstream out(file);

I get this error, cannot convert parameter 1 from wchar * to const char * when using the following write function to write hexadecimal data to a file

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

how can we convert wchar_ * to const char * for the write function to work.

Thank.

+5
source share
2 answers

You can use the function wcstombslink here .

+3
source

Windows , wchar_t, UTF-16 char, , ANSI. wchar_t, , wchar_t, ANSI.

wchar_t ofstream, wofstream.

+1

All Articles