We are going to share a c++ program to remove vowels from a string If you are a beginner and want to start learning the C++ programming, then keep your close attention in this tutorial as I am going to share a program for c++ program to remove vowels from a string.
Copy the below c++ program and execute it with the help of GCC compiler. At the end of this program, We have shared the output of this program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <bits/stdc++.h> using namespace std; string remVowel(string str) { vector<char> vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}; for (int i = 0; i < str.length(); i++) { if (find(vowels.begin(), vowels.end(), str[i]) != vowels.end()) { str = str.replace(i, 1, ""); i -= 2; } } return str; } // Driver Code int main() { string str = "freewebmentor" cout << remVowel(str) << endl; return 0; } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.