Question: Please make this code can be run #include // For cin, cout #include // Required for vector type #include // For string #include // Required

Please make this code can be run

#include // For cin, cout #include // Required for vector type #include // For string #include // Required for STL algorithms using namespace std; // Function Prototype // Add & to use pass by reference otherwise the changes done in vector by removeShortWords function will //not get reflected in the main function void removeShortWords(vector&); int main() { vector myList; // Define an iterator for the vector textbook p.993 vector::iterator iter; //Given myList.push_back("ABCDEF"); myList.push_back("ABCDE"); myList.push_back("AB"); myList.push_back("A"); myList.push_back("ABC"); myList.push_back("ABCDEFGH"); myList.push_back("ABCEDFGH"); myList.push_back("123"); myList.push_back("12"); myList.push_back("1"); myList.push_back("12345"); // Print out the vector before the sort textbook. page 993 for (iter = myList.begin(); iter < myList.end(); iter++) { cout << *iter << endl; } cout << "****" << endl; //Given function removeShortWords(myList); // Print out the vector after the modify // Strings that have more than three characters. for (iter = myList.begin(); iter < myList.end(); iter++) { cout << *iter << endl; } cout << "****" << endl; system("pause"); return 0; } void removeShortWords(vector &one) {/* Set it is vector of begin. Then, use a while loop. If (*it) of length is equal or less than 3, erase one by one from the beginning. */ vector::iterator it = one.begin(); int index = 0; while (it != one.end()) { if ((*it).length() <= 3) { one.erase(one.begin() + index); } else { index++; it++; } } }

I got vector incompatible error.

Please help me.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!