+ 1
What is the code for this?
input: "I'm feeling so :( but my sister looked so :)" output: "I'm feeling so sad but my sister looked so happy" -- my sister told me to solve this and I have no idea how. She only told me to try using string :/ Please help, thank you in advance!
1 Respuesta
+ 2
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int pos;
cout << "Enter a string: ";
getline(cin, str);
do
{
pos = -1;
pos = str.find(":)");
if (pos != -1)
str.replace(pos, 2, "happy");
} while (pos != -1);
do
{
pos = -1;
pos = str.find(":(");
if (pos != -1)
str.replace(pos, 2, "sad");
} while (pos != -1);
cout << str << endl;
return 0;
}
Won't work on the code playground due to getline()