I have to replace a word into another word using strings for an assignment.
We haven't learned [string.replace], but I'm stuck right now.
Here's the code I have come up with so far:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
usingnamespace std;
int main() {
// Create a text string
string userString = "";
string str1 = "hate";
string finalSentence = "";
// Prompt the user
cout << "This program will repace the word 'hate' into 'love' from any sentences the user enters." << endl;
cout << "Please follow the direction correctly, and type correct input." << endl;
cout << endl << endl;
// Printing the input
cout << "Please enter a sentence: " << endl;
getline(cin, userString);
if(userString.find(userString) = "hate") {
finalSentence += "love";
}
cout << finalSentence << endl;
system("pause");
return 0;
}
Umm thanks for your suggestion but we haven't learned using :: in our source code so I don't think that will work...
Isn't there any other possible way?? :(