c++ - ofstream output of std::map<UnicodeString, UnicodeString> yields addresses not strings -


i have stl map container filled pairs of vcl unicodestring objects. i'm trying dump file code quoted below instead of strings i'm getting file full of hex addresses.

//---------------------------------------------------------------------------  #include <vcl.h> #pragma hdrstop #include <tchar.h> #include <iostream> #include <fstream> #include <map>  //--------------------------------------------------------------------------- winapi _twinmain(hinstance, hinstance, lptstr, int) {       std::map<unicodestring, unicodestring> fm;       fm[u"a"]=u"test";       fm[u"b"]=u"test2";       fm[u"c"]=u"test3";       fm[u"z"]=u"last one";       ofstream out("c:\\temp\\fm.txt");       std::map<unicodestring, unicodestring>::const_iterator itr;       (itr = fm.begin(); itr != fm.end(); ++itr) {           out << itr->first.c_str()<< ",\t\t"<< itr->second.c_str()<<std::endl;       }        out.close();     return 0; } 

yields this:

1f3b624,                1f5137c 1f3b654,                1f513bc 1f3b66c,                1f513fc 1f3b684,                1f258dc 

i've tried various ways of casting c string nothing seems work.

as usual answer quite straightforward, lead @dauphic's comment. using 'narrow stream'. solution use wide stream, surprised discover exists!

the solution change stream declaration to:

std::wofstream out("c:\\temp\\fm.txt"); 

and presto changeo works.

the solution found here


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -