#### Archived

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

# handling backspace with string

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

## 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 on other sites

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 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);