std::string += not working

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 408
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

std::string += not working

 
0
  #1
Apr 10th, 2009
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...
  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?
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 374
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: std::string += not working

 
0
  #2
Apr 10th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 408
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: std::string += not working

 
0
  #3
Apr 10th, 2009
Thanks for the reply, I'll check that out in a little bit, and post results.
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 374
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: std::string += not working

 
0
  #4
Apr 10th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 408
Reputation: sciwizeh is on a distinguished road 
Solved Threads: 22
sciwizeh's Avatar
sciwizeh sciwizeh is offline Offline
Posting Pro in Training

Re: std::string += not working

 
0
  #5
Apr 10th, 2009
Well, now I feel dumb... I forgot the SDL_EnableUNICODE call... thanks
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "
-Albert Einstein
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC