I am currently trying to implement deleting characters from a text field in C++. If the user hits Backspace, the following code is executed. There is currently no cursor, it should just remove the last character…
if (mText.length() > 0){
mText.erase( mText.length() - 1, 1);
// mText.resize(mText.length() - 1);
}
This works fine the first time, but if you hit Backspace again, it does not remove anything.
I printed the mText.length() and it shows that the length never changes. I tried to resize() the string, it works fine, but the first time I hit Backspace it removes 2 characters.
I hope someone can explain this behaviour and help me solving the problem. I dont know much about memory allocation, so please be patient with me 😉
Thanks
opatut
I found my problem using gdb. I found the hidden
\bescape sequence which was added to my string after I removed the last character. It actually stands for the backspace, but it was not interpreted. Thank you for your help!