vendredi 27 mars 2020

Having trouble to add "not" in to the string

#include <iostream>
    #include <string>
    using namespace std;
    string isNOT (string str1);
    int main()
    {
        cout << isNOT("This is me") << endl;
        //This is not me
        cout << isNOT("is is") << endl;
        //is not is not
        cout << isNOT("What is yellow?") << endl;
        //What is not yellow?
        return 0;
    }

string isNOT (string str1){
            int lens = str1.size();
            string result;
            string NOT1 = "not ";
            if (str1.find("is")){ //checks if has "is"
                for (int i = 0; i < lens; ++i) { 
                    if (str1 == "is"){
                    result = str1.insert(i + 1, NOT1); //suppose to append not into the string
                    }
                }
            }
         return result;
        }

Aucun commentaire:

Enregistrer un commentaire