Start New Discussion within our Software Development Community

I have a few questions that I was hoping somone here could answer.

1. how can i pause my cout output? or is it possible to do it without calling a system command

2. is there a way to clear the console screen without makeing specific os comands?

3. does any one know a quick and easy way to clear the screen without calling the system() function?

4. is there a way to test for the operating system?

>1. how can i pause my cout output? or is it possible to do it without calling a system command
Ask for input and discard it:

cout<<"Press enter to continue.";
cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
cin.get();

The call to cin.ignore() makes sure that there's no unwanted data in the stream and the call to cin.get() performs a blocking read for the next character. For the cin.ignore(), you need to include <limits> as well as <iostream>.

>2. is there a way to clear the console screen without makeing specific os comands?
Sure. How well it works is debatable though:

const int scr_height = 24;

void clrscr()
{
  for ( int i = 0; i < scr_height; i++ )
    cout<<'\n';
  cout<<flush;
}

>3. does any one know a quick and easy way to clear the screen without calling the system() function?
Yes, don't.

>4. is there a way to test for the operating system?
The only portable way is to require each operating system to define a unique name, then test for it:

#if defined(POSIX)
  #include "posix.h"
#elif defined(WINDOWS)
  #include "win.h"
#elif defined(MAC)
  #include "mac.h"
#endif

Note that those names are not standard, so it's up to your application to specify what they should be and make sure that they're defined in any specific port of the program.

This article has been dead for over six months. Start a new discussion instead.