I used to do this while I used ASCII characters, but now I need to use UNICODE, and I couldn't find the answer after googling some, and searching the forums.
1 2 3 4
std::stringstream ss;
int some_int = 45;
ss << "Some text = " << some_int << "\n";
do_something_with_the_text ( ss.str() ); //takes std::string
This worked fine in ASCII but when I try the same in Unicode:
ok, so w_do_something_with_the_text takes a wstring to render a unicode string onto the screen.
1 2 3 4 5 6
//something like this
for(int c = 0; c < str.size(); c++)
{
int character_code = str[c];
render(characters[character_code]);
}
With ASCII it works with unicode nothing shows up on screen, which indicates that there's no such character in the font. With wstring the rendering works fine. To add I can print the wstringstream with wcout. Is there a conversion issue between wstringstream and wstring?
no it doesn't, same thing happens
I use kubuntu 11.04 64bit, the IDE is kdevelop 4 with latest compiler
a font consists of a character map which contains characters that you can access using their character code. I think that because ws.str() returns a basic_stringstream<wchar_t> the character codes get messed up. so is there a way to convert a wstringstream to a wstring preserving the character codes, or adding non-string stuff as characters to strings? like I added some_int to ws
The code seems OK (about the wstringstream). You are probably getting an OK wstring. Most likely the problem is with render or the font selected. Since I don't know linux, I cannot help any further. I recommend that you post in the Linux forum (or transfer this post there).
ok, I transferred... I think that the rendering code is ok, because if i use plain wstring I can render all the characters on my keyboard, which indicates that the font does contain those characters (so it should be ok too)
ok, I wrote a small example which writes out wstrings and wstringstreams and their character codes. Since all codes are the same and in the previously mentioned rendering function I get the same codes I guess the rendering function is wrong...
I finally solved it, can't believe how stupid the mistake was... I swapped buffers before drawing the text, and since in the beginning of the next frame I clear the back buffer the text gets cleared too... this was an epic 2 days of searching where I messed up... Well thanks for all the help guys!