/* Returns true if the given string contains digit(s), false otherwise */ bool contains_number(const string& str) { for (int k = 0; k < str.size(); k++) if (isdigit(str[k])) return true; return false; }
while (getline(ss, word, ' ')) & //read next word if (!contains_number(word)) //check if it contains a number { result.append(word); //add it to the resulting string if not result.append(" "); } return result; }
int main() { string str = "A fat 215 cat sat on 14rats and 8ate8 himself"; cout << "Original string:" << endl; cout << '\t' << str << endl;
cout << "A string with words containing numbers removed:" << endl; cout << '\t' << remove_words_with_numbers(str) << endl; return 0; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment