68 774
Assignments Done
Successfully Done
In January 2019

Answer to Question #56109 in C++ for Rebekah

Question #56109
Hey, please help how can I replace underscore with characters and memorize all the guessed letters..
Expert's answer
#include <iostream>
#include <String>

using namespace std;

void replace(string & str, const string & from, const string & to)

int start_pos = 0;

while((start_pos = str.find(from, start_pos)) != str.npos)
str.replace(start_pos, from.length(), to);
start_pos += to.length();

int main()
string text, result;

result = text;

replace(result, "_", " ");

cout<<"Orginal text: "<<text<<endl;
cout<<"Result text: "<<result<<endl;


return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


10.11.15, 10:55

Thank you so much.. I really appreciate it. I'm sorry for not being specific at first. Actually, I have project and the project asked to do hangman game. Firstly, I have to compare the country name with the user guessed letter. But, at the same time I have to display the underscore to represent the hidden country name. Once the user enter one of the correct country name, then how can I replace the underscore with correct letter and correct position?

Leave a comment

Ask Your question

Privacy policy Terms and Conditions