Remove last character from C++ string

后端 未结 10 1258
慢半拍i
慢半拍i 2021-01-29 19:50

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

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

10条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 20:29

    For a non-mutating version:

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

提交回复
热议问题