views:

71

answers:

0

I have an C++ Windows Mobile 6 application that is converting a wide-character array to a narrow-character array. I have no problems going from narrow to wide, but when I go from wide to narrow, the conversion fails as in the example below:

const char* testA = "This is a test";
std::wstringstream testW;
testW << testA;
NKDbgPrintfW( L"test A->W: %s\n", testW.str().c_str() );

// test A->W: This is a test

const wchar_t* test2W = L"This is a test";
std::stringstream test2A;
test2A << test2W;
NKDbgPrintfW( L"test W->A: %S\n", test2A.str().c_str() );

// test W->A: 0x000f8498

I understand that I can use std::ctype::narrow to accomplish this. What I'm wondering is why this method only works in one direction.

Thanks, PaulH