wchar_t *CMain::ToWideString(const std::string str) {
int length = str.size() + 1;
wchar_t *buffer = new wchar_t[length];
::mbstowcs(buffer, str.c_str(), length);
return buffer;
}
void CMain::SetWindowCaption() {
std::ostringstream sstream;
sstream << driver->getFPS();
std::string string = "Demo (" + sstream.str() + ")";
wchar_t *buffer = ToWideString(string);
device->setWindowCaption(buffer);
delete[] buffer;
}
Proper method for converting to and from wchar_t*
Hello everyone, I'm currently using the Irrlicht game engine right now. All the text in the engine uses wchar_t* so text that the gui will display for example must be wchar_t*. This has become somewhat of a pain, as when I have to convert a numeric value to a string I have to use streams and then convert to wchar_t* and then after I'm done with the string I have to delete it myself, It seems like quite a heavy procedure just for writing text to the screen. For instance this code displays the fps as the window title.
I also don't really like the fact that I'm using ::mbstowcs which is depreciated. Anyways is there a simpler way I can do this (converting numeric values to wchar_t*) without using old depreciated functions if possible?
Thanks for any help in advance.
Quote:Original post by AsOne
I also don't really like the fact that I'm using ::mbstowcs which is depreciated. Anyways is there a simpler way I can do this (converting numeric values to wchar_t*) without using old depreciated functions if possible?
Thanks for any help in advance.
string & ostringstream are type aliases (typedefs) for class templates, the real ones are called basic_string and basic_ostringstream, if you want the wide character version of these then there is a type alias for them wstring, and wostringstream.
Don't bother converting just use std:wstring and std::wstringstream to do all your formatting
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement