text: Reverse vowels in a given string | C ++ program to reverse order of vowels ; utility function to check for vowel ; Function to reverse order of vowels ; Storing the vowels separately ; Placing the vowels in the reverse order in the string ; Driver function
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char c ) { return ( c == ' a ' c == ' A ' c == ' e ' c == ' E ' c == ' i ' c == ' I ' c == ' o ' c == ' O ' c == ' u ' c == ' U ' ) ; } string reverseVowel ( string str ) { int j = 0 ; string vowel ; for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) if ( isVowel ( str [ i ] ) ) vowel [ j ++ ] = str [ i ] ; for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) if ( isVowel ( str [ i ] ) ) str [ i ] = vowel [ -- j ] ; return str ; } int main ( ) { string str = " hello ▁ world " ; cout << reverseVowel ( str ) ; return 0 ; }