I want to take some input for a game, and delete the last letter from the string after pressing backspace. I'm not sure if I should do text.end -1
, or +1
to end
to do so:
if (GetAsyncKeyState(VK_BACK))
text.erase(text.end - 1, text.end);
std::string
actually has a pop_back()
method! So you can do:
if (GetAsyncKeyState(VK_BACK) && !text.empty()) { text.pop_back(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With