SFML community forums

Help => System => Topic started by: Fox3 on June 13, 2010, 10:42:51 pm

Title: Event.Text.Unicode problem
Post by: Fox3 on June 13, 2010, 10:42:51 pm
How do I convert it to string?
Title: Event.Text.Unicode problem
Post by: Laurent on June 13, 2010, 10:50:14 pm
Three possibilities:
- if you're interested in ASCII only, make sure that the value is lesser than 128 and cast the value to a char
- if your locale is Latin-1 (or compatible), you can safely cast to char with values up to 255
- otherwise, if you want a real conversion from UTF-32 to your current 8-bits locale, you have to use the functions in sf::Unicode

Most people don't care about non-ASCII or non-Latin-1 characters, and just do a cast.
Title: Event.Text.Unicode problem
Post by: Fox3 on June 13, 2010, 11:01:37 pm
It doesnt work :(
Or I did it wrong ^^' Sorry I'm new to this;
Code: [Select]
if(event.Type == sf::Event::TextEntered)
{
std::string str;
if(event.Text.Unicode < 256)
{
str = (std::string)event.Text.Unicode;
}
titlein.addinput(str);
}


The error is
Quote
error: invalid conversion from `sf::Uint32' to `const char*'
Title: Event.Text.Unicode problem
Post by: Laurent on June 13, 2010, 11:03:17 pm
I didn't say "cast to string", I said "cast to char". Indeed this is a single character, not a string.

Code: [Select]
str += static_cast<char>(event.Text.Unicode);
Title: Event.Text.Unicode problem
Post by: Fox3 on June 13, 2010, 11:03:58 pm
Oh sorry, my bad. Thanks :)