Make Command prompt reset?

Aug 1, 2014 at 5:04pm
Hey guys, I am creating a program that is quite long and requires much user input.

Is there a way to prevent the command prompt from being so long that the user has to scroll up and down just to see the content?

Is there a way to RESET the command prompt while the program is still executing
so that the next statement appears on line 1 of the command prompt instead of line 20?

(trying to be descriptive)
EXAMPLE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()

{
string response;

cout << "How Are You"? << endl;
cin >> response;

cout << "That is Great" << endl;
cout << "Where are you from" << endl;

cin >> response;
cout << "Oh wow. I would like to go there one day" << endl;

cout << "Have you ever played Chess??" << endl;//Place this on Line1 of Command prompt
cin >> response;

cout << "I LOVE chess :)" << endl;

return 0;
}
Last edited on Aug 1, 2014 at 6:21pm
Aug 1, 2014 at 5:22pm
If you do reset, then you cannot "just see all content" any more.

Terminals have a size. That many lines they do show simultaneously.
Separately, they have buffer size. That many lines they remember. When buffer is larger than the window, scrolling lets you go back.
Enough output, and the oldest lines will be forgotten, no matter what.

Terminals can be communicated with to perform some operations. The problem is that there are several different terminals and they don't talk the same language. A better, more portable option is to use a library that offers more operations and may communicate with more than one terminal type. ncurses might be such library.
Aug 1, 2014 at 7:42pm
I'm not sure how I could do that -- but Thanks for your input
Aug 1, 2014 at 8:34pm
@dlundy1

If you're not needing to see the previous command prompts, you could just clear the screen, with
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 );
  }


or use a system call, though that's not a good option, but it is AN option.
Topic archived. No new replies allowed.