Answer to Question #40757 in C++ for mpho

Question #40757
returns a string that has all occurrences of a given character
removed.
1
Expert's answer
2014-05-01T11:54:53-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS