954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Flashing the output to the screen for a limited time

hi you all..

i want to flash the output message to the screen for a limited time. can you plz help me ?

is there something in iomanip, or should i do something with system("pause") and system("clear").. although the latest dont seem to me like a good solution ..

ronjustincase
Newbie Poster
12 posts since Dec 2008
Reputation Points: 11
Solved Threads: 2
 

Look up the Sleep function to use as a delay for the message. To clear the screan, you can either use the "system("cls"), or better, do it manually:

void Clear() {
  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 );
}
William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

ok, the first thing works, e.g.

for(int i=0; i<10; i++) {
   cout << i; 
   sleep(3);
   system("clear");
}


but have no understanding on your second soluction. Is there a lib that should i use;

thanks for your reply

ronjustincase
Newbie Poster
12 posts since Dec 2008
Reputation Points: 11
Solved Threads: 2
 

That is a windows only solution to clearing the screen, if you're using linux, you should either use system("clear") or use a portable library like ncurses.

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

i am with opensuse 11 and system("clear") works
(system("pause")) donot work)

anyway thank you very much for your reply.

ronjustincase
Newbie Poster
12 posts since Dec 2008
Reputation Points: 11
Solved Threads: 2
 

Using system() commands is not a good idea, and windows specific functions are not a great solution either. You can use Clock() instead of sleep. Also, check out these special control characters as a way of clearing the screen.

death_oclock
Posting Whiz
393 posts since Apr 2006
Reputation Points: 129
Solved Threads: 45
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You