String ohne Buchstaben
-
Hallo,
vielleicht hat ja jemand eine Tipp für mich.
Ich muss mit Strings arbeiten und weiss nicht wie ich am einfachsten einen String nach Buchstaben durchsuche.
Vielen Dank
Chris
-
#include <string> #include <iostream> #include <algorithm> #include <cctype> using namespace std; bool isNotAlpha(char c) { return !(isalpha(c)); } int main() { string foo("bl%u6bb!s"); string::iterator iter = remove_if(foo.begin(), foo.end(), isNotAlpha); foo.erase(iter, foo.end()); cout << foo; }