Created
October 11, 2013 13:49
-
-
Save ravichandrae/6934964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
void removeChars(string &str, char ch) | |
{ | |
int i; | |
int resInd = 0; //Result string index | |
for( i = 0; i < str.length(); i++ ) | |
{ | |
//retain str[i] only if it is not ch | |
if( str[i] != ch ) | |
{ | |
str[resInd] = str[i]; | |
resInd++; | |
} | |
} | |
//Resize the string so that chars beyond resInd will be erased. | |
str.resize(resInd); | |
} | |
int main() | |
{ | |
string str; | |
getline(cin, str); | |
char removeCh; | |
cin >> noskipws >>removeCh; | |
cin >>skipws; | |
removeChars(str, removeCh); | |
cout<<str; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment