I am learning C++. Today I have written a code to remove vowels form a string. It works fine in some tests. But this test is failing to remove "u" from a string. M
Here's how you can do it more easily:
#include
#include
#include
#include
#include
constexpr auto isVowel(unsigned char const ch) noexcept {
constexpr std::array vowels{
'a', 'e', 'i', 'o', 'u',
};
return std::find(vowels.begin(), vowels.end(), std::tolower(ch)) !=
vowels.end();
}
int main() {
std::string str = "Tour";
str.erase(std::remove_if(str.begin(), str.end(), isVowel), str.end());
std::cout << str << '\n';
}
Try online