I am writing a program to read in a line of text and then replace all four letter words with the word 'love'. I am getting the following compiler error:
love.cpp: In function ‘void replace(std::vector<char, std::allocator<char> >&)’:love.cpp:60: error: ISO C++ forbids comparison between pointer and integer
line 60 is the while statement in the replace function.
I am hoping someone could point me in the right direction. Thank you in advance.
Code:#include <iostream> #include <vector> using namespace std; void introduction(); //Explains what the program does void get_input(vector<char>& v); //Asks user to input text void replace(vector<char>& v); //Replaces all four letter words with the word love. void output(vector<char> v); //Outputs new sentence. int main() { vector<char> v_input; introduction(); get_input(v_input); replace(v_input); output(v_input); return 0; } //uses iostream void introduction() { cout << "This program will ask the user to input a sentence and\n" << "then will output the sentence with all four letter words\n" << "replaced with the word 'love'\n" << endl; } //uses iostream //uses vector void get_input(vector<char>& v) { char tmp; cout << "Please type in a sentence:\n"; cin.get(tmp); do { if (!cin.get(tmp)) //breaks if character is not able to be read in break; v.push_back(tmp); }while (tmp != '\n'); } //uses iostream //uses vector void replace(vector<char>& v) { int j, count; for (int i = 0; i < v.size(); i++) { j = i + 1; // now checking to see if the next word is = 4 letters while (v[j] != '\n' || v[j] != ' ' || v[j] != '.' || v[j] != ',' || v[j] != "") { count++; j++; } if (count == 4) //replaces 4 letter word with 'love' { v.push_back('l'); v.push_back('o'); v.push_back('v'); v.push_back('e'); } i = i + j; } } //uses iostream //uses vector void output(vector<char> v) { cout << endl << "The new sentence with the words replaced is:\n"; for (int i = 0; i < v.size(); i++) { cout << v[i]; } cout << endl; }



LinkBack URL
About LinkBacks



