c++ – TCHAR to std :: string conversion

Question:

TCHAR *tchar;
std::string s = "";
s = tchar;

How to convert? I have no strength to look for anything

Answer:

TCHAR is dependent on the used encoding, you need to do a macro check:

TCHAR *tchar;
std::string s;

#ifndef UNICODE
    s = t;
#else
    std::wstring wStr = t;
    s = std::string(wStr.begin(), wStr.end());
#endif

std::cout << str << std::endl;

Well, or if you want it to work only for you:

TCHAR *tchar;
std::wstring wStr = t;
std::string s = std::string(wStr.begin(), wStr.end());
Scroll to Top