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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -