66 819
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #40757 in C++ for mpho

Question #40757
returns a string that has all occurrences of a given character
removed.
Expert's answer
#include <cstring>
#include <iostream>
using namespace std;
string removeAll (string s, char c)
{
for (int i = 0; i < s.length(); i++)
  if (s[i] == c)
s.erase(s.begin() + i--);
return s;
}
int main() {
string s = "I have a doggie ttttttttttt";
char c = 't';
cout << removeAll(s, c);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions