Getting an error while reversing vowels in a string : <p>I know there are similar questions about this topic but I wanted to know error in my approach.</p>

<p>I'm writing a code to reverse vowels in a string. I first took all the vowels of a string into a vector and then I looped the string from backwards by replacing the vowels but I keep getting an error.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

using namespace std;

string reverseVowels(string s)
{
    vector&lt;char&gt;v;
    vector&lt;char&gt;v2;
    char c;
    for (int i = 0; i &lt; s.size(); i++)
    {
                //taking all the vowels of the string into a vector
        if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')
        {
            v.push_back(s[i]);
        }
    }

        //reversing the vowels of the string
    for (int i = s.size() - 1; i &gt;= 0; i--)
    {
        if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')
        {
            s[i] = v[i];  //Getting an error here
        }
    }
    return s;
}

int main()
{
        //Required output is "holle"
    string s = "hello";
    string p = reverseVowels(s);
    cout &lt;&lt; p &lt;&lt; endl;
    return 0;
}
</code></pre>
