![]() |
In C++, strings are stored as the std::string class objects. In this article, we will look at how to remove the last character from this C++ string object. For Example, Input: Hello! Geeks Remove the Last Character from a String in C++To remove the last character from a string, we can use the pop_back() function which is used to pop the character that is placed at the last in the string and finally print the string after removal. C++ Program to Remove the Last Character from a StringThe below example demonstrates the use of the pop_back() function to remove the last character from the string. C++
Output
Before deletion string is : Hello,Geeks String after removing the last character: Hello,Geek
We can also use the erase() and resize() function to remove the last character from a string. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |