비주얼 C++에서 string을 LPWSTR (wchar_t*)로 바꾸기
절름발이 프로그래머/C언어, C++ 과 Visual C++ / 2009. 3. 6. 15:11
C++ 표준 문자열 string 객체를 wchar_t* 타입의 문자열로 바꾸는 함수
wchar_t* string2LPWSTR(const std::string input)
{
// null-call to get the size
size_t needed = ::mbstowcs(NULL,&input[0],input.length());
// allocate
std::wstring output;
output.resize(needed);
// real call
::mbstowcs(&output[0],&input[0],input.length());
// You asked for a pointer
wchar_t *pout = output.c_str();
return pout;
}