this is my issue. I am compiling with g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
I would like to check every element of the string, and copy it only if it is a consonant.
This is how I try to do that: This is just a function to select vowels:
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;
}
This is the bit of code that does not work. Specifically, inside the ss.length()
appears to be 0, and the string ss contains no character, but they are correctly printed inside the while loop.
main(){
int i=0, c=0;
string ss, name;
cout << "insert name\n";
getline(cin, name);
while (i<int(name.length())){
if (!_is_vowel(name[i])){
cout << name[i]<< "\t";
ss[c]=name[i];
cout << ss[c]<< "\n";
c++;
}
i++;
}
cout << int(ss.length())<<endl;
cout << ss;
}
Could anyone explain to me where I am wrong or give me some reference? Thank you in advance