Why do I get zero length for a string filled element by element? : <p>this is my issue. I am compiling with g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0</p>

<p>I would like to check every element of the string, and copy it only if it is a consonant.</p>

<p>This is how I try to do that:
This is just a function to select vowels:</p>

<pre><code>bool _is_vowel(char a){
    if (a=='a' || a=='A' || a=='e' || a=='E' ||a=='i' || a=='I' || a=='o' || a=='O' || a=='u' || a=='U' || a=='y' || a=='Y')
        return true;
    else return false;
}
</code></pre>

<p>This is the bit of code that does not work. Specifically, inside the <code>ss.length()</code> appears to be 0, and the string ss contains no character, but they are correctly printed inside the while loop.</p>

<pre><code> main(){
    int i=0, c=0; 
    string ss, name;
    cout &lt;&lt; "insert name\n";
    getline(cin, name);
    while (i&lt;int(name.length())){
       if (!_is_vowel(name[i])){
          cout &lt;&lt; name[i]&lt;&lt; "\t";
          ss[c]=name[i];
          cout &lt;&lt; ss[c]&lt;&lt; "\n";
          c++;
        }
        i++;
    }    

    cout &lt;&lt; int(ss.length())&lt;&lt;endl;
    cout &lt;&lt; ss;                
    } 
</code></pre>

<p>Could anyone explain to me where I am wrong or give me some reference?
Thank you in advance</p>
