Code: Select all
wchar_t stringToWchart(const std::string value)
{
// value to hold converted string
c8 char_value[64];
// convert from string to char
strcpy_s(char_value,
std::strlen(value.c_str()) + 1,
value.c_str());
// filled with number of characters converted
size_t num_of_converted_wchars = 0;
// value to hold converted wchar_t
wchar_t wchar_value[64];
// convert from char* to wchar_t*
mbstowcs_s(&num_of_converted_wchars,
wchar_value,
std::strlen(char_value) + 1,
char_value,
_TRUNCATE);
// return value
return *wchar_value;
}
Code: Select all
c8 wchartToChar(const wchar_t* value)
{
// convert from wchar_t* to char*
size_t convertedChars = 0;
// value to hold converted wchar
c8 char_value[64];
// convert from wchar_t* to char*
wcstombs_s(&convertedChars,
char_value,
std::wcslen(value) + 1,
value,
_TRUNCATE);
// return converted char
return *char_value;
}