C++: convert TCHAR array to std::string -


i want convert tchar array std::string. after searching internet, did way:

tchar filename[260]; getprocessname(     reinterpret_cast<dword>(processid),      filename,      max_path     ); std::wstring tmpwstring( filename ); std::string result( tmpwstring.begin(), tmpwstring.end() );  std::cout << "the length of tmpwstring is: " << tmpwstring.length() << std::endl; 

this gives me tmpwstring of length 0. however, pure coincidence, added sleep function before conversion, goes smoothly, , can conversion result properly:

tchar filename[260]; ::sleep(500); getprocessname(     reinterpret_cast<dword>(processid),      filename,      max_path     ); std::wstring tmpwstring( filename ); std::string result( tmpwstring.begin(), tmpwstring.end() );  std::cout << "the length of tmpwstring is: " << tmpwstring.length() << std::endl; std::cout << "this resulted string: " << result << std::endl; 

i didn't it. why adding sleep makes work while omitting causes zero-length wstring? didn't want include sleep in code after all. explain this? working environment visual studio 2010, on virtual machine windows xp. character set of configuration properties of vs2010, didn't specify set. in advance.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -