943,879 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 638
  • C++ RSS
Apr 10th, 2009
0

std::string += not working

Expand Post »
Hello all, I'm trying to make a simple text box with SDL, I have loosely based it off of The Lazy Foo Tutorial on sting input, but this code doesn't seem to work...
C++ Syntax (Toggle Plain Text)
  1. if(event.type==SDL_MOUSEBUTTONDOWN){
  2. if(isIn(event.button.x,event.button.y)){
  3. hasFocus=true;
  4. } else {
  5. hasFocus=false;
  6. }
  7. }
  8. if(event.type==SDL_KEYDOWN){
  9. if(hasFocus){
  10. if(event.key.keysym.sym!=SDLK_BACKSPACE){
  11. str+=(char)(event.key.keysym.unicode);
  12. } else {
  13. if(str.length()!=0){
  14. str.erase(str.length()-1);
  15. }
  16. }
  17. }
  18. }
From a debug the focusing works fine, as is the display, but for some reason the character is not getting appended. What can I do to fix this?
Reputation Points: 73
Solved Threads: 22
Posting Pro in Training
sciwizeh is offline Offline
423 posts
since Jun 2008
Apr 10th, 2009
0

Re: std::string += not working

Maybe make sure that conversion is going alright?

Output (char) (event.key.keysym.unicode) or something.

ASCII chars in UTF-8 might be something like, {\x00\x<ASCII-code>}, in that case, you're appending \x00 . It's my best guess.
Last edited by Clockowl; Apr 10th, 2009 at 6:22 pm.
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Apr 10th, 2009
0

Re: std::string += not working

Thanks for the reply, I'll check that out in a little bit, and post results.
Reputation Points: 73
Solved Threads: 22
Posting Pro in Training
sciwizeh is offline Offline
423 posts
since Jun 2008
Apr 10th, 2009
0

Re: std::string += not working

From the reference:

"... The unicode field is only used when UNICODE translation is enabled with SDL_EnableUNICODE. ... "

I suppose you did that, but below there is code on how to translate that code back to ASCII.

Buuuuttt as he also notes, if you're not using unicode, don't enable it. Why not grab the .sym instead and convert that? Hope it helps anyway.
Last edited by Clockowl; Apr 10th, 2009 at 6:42 pm.
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Apr 10th, 2009
0

Re: std::string += not working

Well, now I feel dumb... I forgot the SDL_EnableUNICODE call... thanks
Reputation Points: 73
Solved Threads: 22
Posting Pro in Training
sciwizeh is offline Offline
423 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: c++ password protection
Next Thread in C++ Forum Timeline: Programming without XP Pro.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC