So for my first assignment of the semester I need to write a program that:
1.) Asks the user to input a string
2.) Asks them to replace part of the string
3.) Have the program prompt "Yes" or "No" on whether the user wants the program to restart, if yes then it does and if no then it ends.(I haven't written this part of the code yet because it seems like the easiest and I can do at the end. It's a simple loop with a boolean value right?)
Okay so obviously I don't want you guys to just give me the answers because I still want to learn, but if you could help me onto the right track that would be great!
Thanks a lot!
This is what I have so far minus the restart function and loops:
I tried to test this and received errors. I am unsure of how to code this search and replace function.
#include <iostream>
#include <cstring>
using namespace std;
void replaceString (string, string);
int main()
{
// Ask user to input a string
// Create a function that reads a string, locates a portion, and replaces it
// with a new string
string s1, s2, s3;
cout << "Please input a string: " << endl;
getline(cin,s1);
cout << "What would you like to replace? " << endl;
getline(cin,s2);
cout << "What would you like to replace '" << s2 << "' with? " << endl;
getline(cin,s3);
replaceString (string& s1, string& s2)
system("pause");
return 0;
}
void replaceString (string& s1, string& s2)
{
int loc;
loc = s1.find(s2);
s1.replace(loc,s3);
cout << s1 << endl;
}