title: C++ Return Vowels in String using subString
body: <p>I'm new to c++... I'm trying to make a function that takes in a string and returns only the vowels in the string. I need to use substrings to perform this. If I use a word with only 1 vowel the function runs correctly... however I've tested a few other strings and it does not work. Do any of you have some suggestions? Thanks so much! </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  string vowel_search(string str)
  {
      string test = str;
      string result = "";
      for (int i = 0; i &lt; test.length(); i++)
      {
          if (str[i] == 'a' || str[i] == 'A'||
              str[i] == 'e' || str[i] == 'E' ||
              str[i]== 'i'|| str[i] == 'I' ||
              str[i] == 'o' || str[i] == 'O' ||
              str[i] == 'u' || str[i] == 'U')
          {
            result += test.substr(i, i);
          }
       }
       return result;
  }
  int main() {
  string strWord = "Aaron";
  string str1 = vowel_search(strWord);
  cout &lt;&lt; str1 &lt;&lt; endl; // prints out: aon
  
  string strWord1 = "Harry";
  string str2 = vowel_search(strWord1);
  cout &lt;&lt; str2 &lt;&lt; endl; //prints out: a -- Correct
  
  string strSentence = "Harry is Funny";
  string str3 = vowel_search(strSentence);
  cout &lt;&lt; str3 &lt;&lt; endl; //prints out: ais Fununny
  
  return 0;
  }
  </code></pre>