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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -