본문 바로가기
개발/C 언어

you can convert a std::wstring to a const wchar_t * using the c_str member function

by 철권 2023. 2. 9.
728x90
#include <cstdlib>

// ...

std::wstring wStr;
const wchar_t *input = wStr.c_str();

// Count required buffer size (plus one for null-terminator).
size_t size = (wcslen(input) + 1) * sizeof(wchar_t);
char *buffer = new char[size];

#ifdef __STDC_LIB_EXT1__
    // wcstombs_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined
    size_t convertedSize;
    std::wcstombs_s(&convertedSize, buffer, size, input, size);
#else
    std::wcstombs(buffer, input, size);
#endif

/* Use the string stored in "buffer" variable */

// Free allocated memory:
delete buffer;

 

728x90
반응형

'개발 > C 언어' 카테고리의 다른 글

CString 사용 헤더  (0) 2022.11.29
char to LPCWSTR  (0) 2022.10.11
일정관리 PDM  (0) 2022.10.07
MSBuild 오류 MSB8040  (0) 2022.09.21
gsjava CString 상호 변경하기 unicode 와 ansi, std::string  (0) 2021.04.26