C++ How To Remove Vowels from a String
Remove Vowels from a String
Build a new string that only gets the characters that are not vowels:
Example
string text = "Hello World";
string result = "";
for (char c : text) {
char lower = tolower(c);
if (lower != 'a' && lower != 'e' && lower != 'i' && lower != 'o' && lower != 'u') {
result += c;
}
}
cout << result;
Explanation:
The loop checks each character. If it is not a vowel, it is added to result with +=.tolower() makes sure that uppercase vowels are removed too.