How to Remove Last Character From C++ String? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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! GeeksOutput: Hello! GeekRemove 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++ // C++ program to remove the last character from a string. #include <iostream> #include <string> using namespace std; int main() { //declaring a string string myString = "Hello,Geeks"; //printing string before deletion cout << "Before deletion string is : " << myString << endl; // Checking if the string is not empty before removing the last character if (!myString.empty()) { myString.pop_back(); } //printing the string after deletion cout << "String after removing the last character: " << myString << endl; return 0; } OutputBefore deletion string is : Hello,Geeks String after removing the last character: Hello,Geek Note: pop_back() function works in-place meaning the modification is done in the original string only which results in a reduction of the size of the original string by one. We can also use the erase() and resize() function to remove the last character from a string. Comment More info O officialsi8v5f Follow Improve Article Tags : C++ Programs C++ cpp-string CPP Examples Explore C++ BasicsIntroduction to C++3 min readData Types in C++7 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++10 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library2 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like