I was doing this exercise on writing a program that takes in words and prints the list of words without repetition. However, I am stuck when the question further asked to replace a word of choice(that I dislike) to "Bleep".
Here is the code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<string>words;
string temp;
while (cin>>temp)
words.push_back(temp);
cout << "Number of words: " << words.size() << "\n";
for (int i = 0; i<words.size(); ++i)
if(i == 0 || words[i-1] != words[i])
cout << words[i] << '\n';
return 0;
}
How can I add codes to change a string input by the user for example 'cute' to 'Bleep'? Thank you so much.
if/elseinside thewhileloop... BTW, your question kinda leaves the impression that you're asking us to do your homework for you.