0% found this document useful (0 votes)
24 views

14. Write a C++ Program to Remove the Vowels from a String

Uploaded by

Ajay kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

14. Write a C++ Program to Remove the Vowels from a String

Uploaded by

Ajay kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

14.

Write a C++ Program to Remove the


Vowels from a String
Program to remove vowels from a String
Last Updated : 16 Feb, 2023



Given a string, remove the vowels from the string and print the
string without vowels.
Examples:
Input : welcome to geeksforgeeks
Output : wlcm t gksfrgks

Input : what is your name ?


Output : wht s yr nm ?
A loop is designed that goes through a list composed of the
characters of that string, removes the vowels and then joins
them.
Implementation:

Try it on GfG Practice

 C++14
 Java
 Python3
 C#
 Javascript

// C++ program to remove vowels from a String

#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 -= 1;

return str;

// Driver Code
int main()

string str = "GeeeksforGeeks - A Computer"

" Science Portal for Geeks";

cout << remVowel(str) << endl;

return 0;

// This code is contributed by

// sanjeev2552

// and corrected by alreadytaken

Output
GksfrGks - Cmptr Scnc Prtl fr Gks
Time Complexity: O(n), where n is the length of the string
Auxiliary Space: O(1)
We can improve the above solution by using Regular
Expressions.
Implementation:
 C++
 Java
 Python3
 C#
 Javascript

// C++ program to remove vowels from a String


#include <bits/stdc++.h>

using namespace std;

string remVowel(string str)

regex r("[aeiouAEIOU]");

return regex_replace(str, r, "");

// Driver Code

int main()

string str = "GeeeksforGeeks - A Computer Science Portal for Geeks";

cout << (remVowel(str));

return 0;

// This code is contributed by Arnab Kundu

Output
GksfrGks - Cmptr Scnc Prtl fr Gks
Time Complexity: O(n), where n is the length of the string
Auxiliary Space: O(1)

You might also like