Answers for "how to erase particular element in string in c++"

C++
3

delete one specific character in string C++

#include <algorithm>
str.erase(std::remove(str.begin(), str.end(), 'a'), str.end());
Posted by: Guest on September-24-2020
0

delete parts of a string c++

#include<iostream>
#include<string>

using namespace std;
int main()
{
   string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   cout << "Initial string: " << text << endl;

   text.erase(10, string::npos);
  // string.erase(pos1, pos2) removes the part of the string between position 1 and 2.
  // In this case, between character 10 and the end of the string.

   cout << "Final string: " << text;
}
Posted by: Guest on July-19-2021

Code answers related to "how to erase particular element in string in c++"

Browse Popular Code Answers by Language