Convert wstring to const *char in c++ -
i have got wstring , want convert const char in order write write function of fstream library. tried following:
std::ofstream out("test.txt", std::ios::out | std::ios::app | std::ios::binary); char mbstr[11]; std::wcstombs(mbstr, strvalue.c_str(), 11); //strvalue wstring out.write(mbstr, 11); ... // have got 4 wstring.
i not sure did, result text file weird:
0.100693 ÌÌ0.000000 ÌÌ0.004094 ÌÌ0.360069 ÌÌ0.086034
any idea how can write wstring in file?
you're converting correctly, you're not writing correctly. out << mbstr;
. you're writing 11 bytes in array no matter what's in there, , strange characters see random junk after area written wcstombs
.
of course, better way might use wofstream
in first place. can insert wide string directly.
Comments
Post a Comment