Remove last character from C++ string

skazhy picture skazhy · Feb 22, 2010 · Viewed 314.9k times · Source

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

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

Answer

mpgaillard picture mpgaillard · May 19, 2013

Simple solution if you are using C++11. Probably O(1) time as well:

st.pop_back();