Can I use str.append to create a new string with no vowels?

  append, c++, iterator, string

I’m doing a practice assignment from codewars.com to create a program that will take a troll’s comments and transform it into a statement with no vowels.

My idea is to get the comment, return all the characters that are not vowels and put it in a new string array using an iterator.

int main()
{
    string troll;
    string disemvoweled;
    
    getline(cin,troll);
    int length= (int) troll.length();
    
    string::iterator it;
    
    for (it = troll.begin();it!=troll.end();it++) {
        if (*it!='a' || *it!='e' || *it!='i' || *it!='o' || *it!='u' || *it!='A' || *it!='E' ||*it!='I' || *it!='O' || *it!='U'){
            disemvoweled.append(*it);
        }
    }
    cout << disemvoweled;

    return 0;
}

I get an error:

no matching function for call to std::__cxx11::basic_string<char>::append(char&)'

My first question is why is the append() not working?

My second question is, without providing any solution, which concept of C++ can help me improve this code? I was thinking perhaps using a container of some sort and popping out a vowel?

Source: Windows Questions C++

LEAVE A COMMENT