system("pause") in any other OS

Hey everyone, I need some help here.

How can I use the pause to make it works in any OS using standar c++ library, I easily found how to do with the cls command, but i cant find how to do with pause.

I mean something like this, if it is possible.
1
2
3
4
5
6
#ifdef _WIN32
    #define CLEAR "cls"
#else
    #define CLEAR "clear"
#endif


Thanks in advance.

As a general rule, it is better to try and avoid the use of system - not only due to OS incompatibilities, but also for security reasons. Instead, consider the following (cross-platform) method for pausing:
1
2
3
4
5
6
#include <iostream>

void pause() {
    std::cin.sync(); // synchronize and clear the buffer
    std::cin.get();  // retrieve a linefeed from the user.
}


As for clearing the screen, the easiest way is simply to do this:
 
std::cout << std::string(80, '\n');


If you really need it, though, there is always the curses library (which provides a bunch of handy functions - look it up), or various platform specific ways. Have a look at this article: http://www.cplusplus.com/articles/4z18T05o/
OK, thank you very much :-D

Btw, another question, to show 2 decimals, is there another way to do besides <<fixed<<setprecision(2)?

Thanks again.
Topic archived. No new replies allowed.