Delete a specific char from string
//Delete a specific char from string,,,,char is 'F' in string= "YOUSUF".the resultant string will be "YOUSU". #include <iostream> #include <string> #include <exception> using namespace std; void DeleteCharFromString(string* str, char c) { if (!str || str->empty()) { throw exception(); } int pos = 0; int new_pos = 0; while (pos < str->length()) { if ((*str)[pos] != c) (*str)[new_pos++] = (*str)[pos++]; else pos++; } *str = (*str).substr(0, new_pos); } int main(int argc, char** argv) { if (argc <= 1) return 0; string str(argv[1]); char c = argv[2][0]; DeleteCharFromString(&str, c); cout << str << endl; }
Passion, patience, perseverance, keep it and move on.

浙公网安备 33010602011771号