How to Remove Last Character From C++ String? Last Updated : 01 Feb, 2024 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 infoAdvertise with us Next Article How to Remove Last Character From C++ String? O officialsi8v5f Follow Improve Article Tags : C++ Programs C++ cpp-string CPP Examples Practice Tags : CPP Similar Reads How to Remove Last Element from Vector in C++? Given a vector of n elements, the task is to remove the last element from the vector in C++.The most efficient method to remove the last element from vector is by using vector pop_back() method. Letâs take a look at a simple example:C++#include <bits/stdc++.h> using namespace std; int main() { 2 min read How to Convert a Single Character to String in C++? A string is a generally made up of a sequence of multiple characters. In this article, we will learn how to convert a single character to a string in C++.Example:Input: c = 'A'Output: s = "a"Explanation: Character c is converted to a string.Input: c = '#'Output: s = "#"Explanation: Character c is co 4 min read How to Extract a Substring from a Character Array in C++? In C++, character arrays are used to store sequences of characters also known as strings. A substring is a part of a string that consists of a continuous sequence of characters from the string. In this article, we will learn how to extract a substring from a character array in C++. Extract a Substri 2 min read How to Remove an Element from the End of a List in C++? In C++, lists are data structures that allow us to store data of the same type in non-contiguous memory locations. In this article, we will learn how to remove an element from the end of a list in C++. Example Input: myList={10,20,30,40,50} Output: List Elements: 10 20 30 40Delete the Last Element f 2 min read How to Reverse a String in C++? Reversing a string means replacing the first character with the last character, second character with the second last character and so on. In this article, we will learn how to reverse a string in C++.ExamplesInput: str = "Hello World"Output: dlroW olleHExplanation: The last character is replaced by 2 min read Like