skazhy skazhy - 11 months ago 107
C++ Question

Remove last character from C++ string

How can I remove last character from a C++ string?

I tried

st = substr(st.length()-1);
But it didn't work.

Answer Source

For a non-mutating version:

st = myString.substr(0, myString.size()-1);