Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Event.Text.Unicode problem  (Read 9387 times)

0 Members and 2 Guests are viewing this topic.

Fox3

  • Newbie
  • *
  • Posts: 10
    • View Profile
Event.Text.Unicode problem
« on: June 13, 2010, 10:42:51 pm »
How do I convert it to string?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event.Text.Unicode problem
« Reply #1 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.
Laurent Gomila - SFML developer

Fox3

  • Newbie
  • *
  • Posts: 10
    • View Profile
Event.Text.Unicode problem
« Reply #2 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*'

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event.Text.Unicode problem
« Reply #3 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);
Laurent Gomila - SFML developer

Fox3

  • Newbie
  • *
  • Posts: 10
    • View Profile
Event.Text.Unicode problem
« Reply #4 on: June 13, 2010, 11:03:58 pm »
Oh sorry, my bad. Thanks :)