writing a basic hangman game that hides part of the output

Hello everyone. I am new to C++ and I am trying to write a basic hangman game, a game without any graphics. What I want the program to do is prompt the first player to enter a word, and then have the second player guess letters that appear in the word. The program works, I just have a question about how information is displayed. When I run the program, the first thing that happens is that player 1 is prompted to enter a word. That player then enters that word. Since the player has entered that word, that word is just sitting on the screen in the window where the program is running. So of course the next player, the player who is supposed to guess what letters appear in the word, can just see the word. This makes the game trivial to play for the second player, of course. Is there some kind of command that will clear the window where the program is running of what has been previously output? Thanks!
try system("cls");
system is bad news - there is an article on this site all about that. IMO, the simplest brute force method is to cout 100 newlines. Put that code into a function.

However, read the article.
@strangelove1221

Here is a ClearScreen function you can use. To use, just call it with
ClearScreen();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <windows.h> // add this into includes, if not already used

void ClearScreen()
  {
   DWORD n;
  DWORD size;
  COORD coord = {0};
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  GetConsoleScreenBufferInfo ( h, &csbi );
  size = csbi.dwSize.X * csbi.dwSize.Y;
  FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
  GetConsoleScreenBufferInfo ( h, &csbi );
  FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
  SetConsoleCursorPosition ( h, coord );
  }
Thank you everyone for the help. I should have thought of just outputting a bunch of blank lines. That ClearScreen function is cool, thanks.
Topic archived. No new replies allowed.