C++ String Exercises: Reverse only the vowels of a given string
19. Reverse Only the Vowels in a String
Write a C++ program to reverse only the vowels of a given string.
A vowel is a syllabic speech sound pronounced without any stricture in the vocal tract. Vowels are one of the two principal classes of speech sounds, the other being the consonant.
Example-1:
Input: w3resource
Output: w3resuorce
Example-2:
Input: Python
Output: Python
Example-3:
Input: Hello
Output: Holle
Example-4:
Input: USA
Output: ASU
Sample Solution:
C++ Code:
Sample Output:
Original string: w3resource After reversing the vowels of the said string: w3resuorce Original string: Python After reversing the vowels of the said string: Python Original string: Hello After reversing the vowels of the said string: Holle Original string: USA After reversing the vowels of the said string: ASU
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program to reverse only the vowel characters in a string while keeping consonants in their original positions.
- Write a C++ program that reads a string, extracts its vowels, reverses them, and then reinserts them into the original string positions.
- Write a C++ program to swap vowels in a string by identifying vowel indices and reversing their order.
- Write a C++ program that processes a string to reverse the order of its vowels while leaving other characters unchanged.
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous C++ Exercise: Length of the longest valid parentheses substring.
Next C++ Exercise: Length of the longest palindrome in a given string.What is the difficulty level of this exercise?