C++ Programming Code Examples C++ > Strings Code Examples count vowels in a string c++ count vowels in a string c++ Write a C++ program which counts numbers of vowels in a given string and tell every index where a vowel is found. Size of array is fixed using the constant variable. User enters a string then a while loop traverse the whole string till null found. In while loop using switch statement we check each character of string one by one either it is matching one of case or not. When a vowel is found check variable value becomes 1 and if condition becomes true and a vowel is found at x index prints on the console. C++ Source code #include <iostream> using namespace std; int main() { const int SIZE = 100; char stringObj[SIZE]; int index= 0; int valueAt = 0; int check = 0; cout<<"Enter a String to find vowel: "; cin.getline(stringObj,100); while(stringObj[index] !='\0') { switch(stringObj[index]) { case 'a': check = 1; case 'e': check = 1; case 'i': check = 1; case 'o': check = 1; case 'u': check = 1; if(check == 1) { cout<<"Vowel "<<stringObj[index]<<" found at index number "<<valueAt<<endl; } check = 0; } valueAt++; index++; } return 0; }