Question about a Hangman program

I'm starting to work on a Hangman game program, and want to know if there is a way to instead of making a new line every time; to just keep modifying the same one.
So instead of a bunch of
if (answer == "A")
{
cout <<" _ _ _ _ A _ _";
}
is there a way to just keep a _ _ _ _ _ _ _ and just if (answer == "A") it just puts in on the appropriate spot, and keeps adding if you keep getting letters right.
yes.
there is a constructor for class string that takes 2 arguments: the first is the number of characters in the string, the second is a char that specifies the filling character.

As an example:
1
2
3
4
//...
string answer = "hangman";  //this is the word to be guessed
int length = answer.length(); //the number of characters in answer (7)
string attempt = string(length, '_'); stores a string consisting of 7 '_' 's 


If the user guesses a correct letter, all you need to do is change the '_' in the position with the actual letter.
Last edited on
So could you write the entire thing for just one guess? I get what you're saying though, thanks.
Topic archived. No new replies allowed.