Remove vowels from a String in C++

C++Server Side ProgrammingProgramming

The following C++ program illustrates how to remove the vowels (a,e, i,u,o) from a given string. In this context, we create a new string and process input string character by character, and if a vowel is found it is excluded in the new string, otherwise the character is added to the new string after the string ends we copy the new string into the original string. The algorithm is as follows;


   Step-1: Input the string
   Step-3: Check vowel presence, if found return TRUE
   Step-4: Copy it to another array
   Step-5: Increment the counter
   Step-6: Print

In pursuance of the above algorithm, the following code in c++ language essayed as following;


#include <iostream>
#include <string.h>
#include <conio.h>
#include <cstring>
using namespace std;
int vowelChk(char);
int main(){
   char s[50], t[50];
   int c, d = 0;
   cout<<"Enter a string to delete vowels\n";
   for(c = 0; s[c] != '\0'; c++) {
      // check for If not a vowel
      if(vowelChk(s[c]) == 0){
         t[d] = s[c];
   t[d] = '\0';
   strcpy(s, t);
   cout<<"String after delete vowels:"<<s;
   return 0;
int vowelChk(char ch){
   if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U')
      return 1;
      return 0;

This C++ program deletes vowels from a string: if the input string is "ajaykumar" then it yields results as "jykmr". Finally, we obtain a string without vowels.


Enter a string to delete vowels
String after delete vowels:jykmr
Published on 29-Nov-2019 15:43:00