I have a function to take a std::string
and change it into a wchar_t*
. My current widen function looks like this
wchar_t* widen(const std::string& str){
wchar_t * dest = new wchar_t[str.size()+1];
char * temp = new char[str.size()];
for(int i=0;i<str.size();i++)
dest[i] = str[i];
dest[str.size()] = '\0';
return dest;
}
This works just fine for standard characters, however (and I cannot believe this hasn't been an issue before now) when I have characters like á, é, í, ó, ú, ñ, or ü it breaks and the results are vastly different.
Ex: my str
comes in as "Database Function: áFákéFúnctíóñü"
But dest
ends up as: "Database Function: £F£k←Fnct■"
How can I change from a std::string
to a wchar_t*
while maintaining international characters?