Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jaggy

handling backspace with string

This topic is 5230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there! My game is almost finished, but I''ve hit a problem while asking the user to add their name to the highscore table. I can get input, but I don''t know how to handle backspaces. I''m using WM_CHAR and I have so far:
...
else if(wParam == VK_BACK)
{
  string getName = Game->getCurrentName();
  Game->setCurrentName(getName);

/* Need something like
    getName--;
or
   getName[getName.size() - 1] = ''/0'';
*/ 


  return 0;
}
I''m on the right lines somewhere I think but I just can''t figure out the syntax. I haven''t used string very much. Can anyone help? Thanks for reading, Jaggy.

Share this post


Link to post
Share on other sites
Advertisement
How about:

getName = getName.left(getname.size() - 1);


I''m not sure if left is the function name but there should be something similar in whichever string class you are using.

Share this post


Link to post
Share on other sites
Thanks for the reply. I didn''t have a .left, but it put me on the right track to something that did work:

getName.resize(getName.size() - 1);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!