C++ string pop_back() Function
Example
Remove the last character of a string:
string txt = "Hello World!";
txt.pop_back();
cout << txt;
Definition and Usage
The pop_back() function removes the last character of a string. The string becomes one character shorter.
The pop_back function is defined in the <string> header file.
Note: Do not use pop_back() on an empty string. The result is undefined (the program can crash).
Syntax
string.pop_back();
Parameter Values
None.
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about strings in our String Tutorial.