I need to convert a const std::wstring * to a UTF-8 encoded const char * and I just can't make it work.
I wrote the code to do that but it isn't working
Code:
//wideData is defined as const std::wstring *wideData
size_t count = 0;
char *convertedChar = new char[wideData->size() + 1];
count = wcstombs(convertedChar, wideData->c_str(), wideData->size());
But while wideData->c_str() looks fine and wideData->size() too, after wcstombs count turns into 4 billion something, and convertedChar is just "". But if I replace the last line with
Code:
count = wcstombs(convertedChar, L"test", wideData->size());
Then count is 4 and convertedChar is "test" so it is working there. What am I doing wrong?
Thanks in advance