In this C++ tutorial, you will learn how to remove last character in the string using string::pop_back() function, with examples.
Remove Last Character in String
string::pop_back() function removes the last character in this string.
ADVERTISEMENT
Syntax
The syntax to remove last character from the string str
is
str.pop_back()
Examples
1. Remove last character from string “apple”
In the following program, we take a string: str
and remove the last character using string::pop_back() function.
C++ Program
#include <iostream> using namespace std; int main() { string str = "apple"; str.pop_back(); cout << str << endl; }
Output
appl Program ended with exit code: 0
Conclusion
In this C++ Tutorial, we learned how to remove last character from this string using string::pop_back() function, with examples.