C++ program to remove the vowels from a string

Removing vowels from a string.

In this article we will learn how to code a C++ program to  remove vowels from a string. To remove vowels first we will take a string as an input from the user then we will check for the vowels by iterating each character of the string through the for loop and if the character iterated is found to be vowel then we will remove that from the string. And then we print the remaining string, without vowels as an output.

C++ program to remove the vowels from a string

Algorithm:

  • Initialize the variables.
  • Accept the input.
  • Initialize for loop.
  • Check and remove the vowels from the string.
  • Store the string without vowels using another for loop.
  • Terminate both for loop.
  • Print the string without vowels.

C++ programming code to remove vowels from a string

 

#include<iostream>
#include<string.h>
using namespace std;

int main()
{
//Initializing variable.
char str[100];
int i,j,len=0;

//Accepting input.
cout<<"Enter a string : ";
cin>>str;
len=strlen(str);

//Accepting input.
for(i=0; i<len; i++)
{
//Checking vowels.
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
{

//Deleting vowels.
for(j=i; j<len; j++)
{
//Storing string without vowels.
str[j]=str[j+1];
}
i--;
len--;
}
}
cout<<"After deleting the vowels, the string will be : "<<str;

return 0;
}

Output :

Enter a string : aaabbbeeeccc

After deleting the vowels, the string will be : bbbccc

Operations on Strings

  • Length of the string without using strlen() function : C | C++ | Java | Python
  • Toggle each character in a string : C | C++ | Java | Python
  • Count the number of vowels : C | C++ | Java | Python
  • Remove the vowels from a String : C | C++ | Java | Python
  • Check if the given string is Palindrome or not : C | C++ | Java | Python
  • Print the given string in reverse order : C | C++ | Java | Python
  • Remove all characters from string except alphabets : C | C++ | Java | Python
  • Remove spaces from a string : C | C++ | Java | Python
  • Remove brackets from an algebraic expression : C | C++ | Java | Python
  • Count the sum of numbers in a string : C | C++ | Java | Python
  • Capitalize the first and last character of each word of a string : C | C++ | Java | Python
  • Calculate frequency of characters in a string : C | C++ | Java | Python
  • Find non-repeating characters in a string : C | C++ | JAVA | Python
  • Check if two strings are Anagram or not : C | C++ | Java | Python
  • Replace a sub-string in a string: C | C++ | Java | Python
  • Count common sub-sequence in two strings : C | C++ | Java | Python
  • Check if two strings match where one string contains wildcard characters : C | C++ | Java | Python
Operations on Strings