for the pause command, try this function, it's most likely safe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#ifdef max() // windows.h library defines a function-like macro with the name of max()
#define _TEMP_MACRO_() max() // store the predefined macro in a new one
#undef max() // undefine the problamatic macro.
#endif
void pause( const char* prompt )
{
std::cin.clear() ; // clear failed/error states of the stream if they are set
if( std::cin.rdbuf()->in_avail() ) // if there are any characters in the input buffer
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ) ; // throw them away
std::cout << prompt ;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ) ;
}
#ifdef _Temp_MACRO_()
#define max() _TEMP_MACRO_() // restore the max() macro.
#undef _TEMP_MACRO_() // undefine the temporary macro.
#endif
|
about the clear screen command, there's no such function in native C++ that does this job, MSDN descriped one in terms of windows API, but when i tried it, it didn't clear the screen, and some unknown phrases appeared, i still use
system("cls");.
system() is described to be
bad as its behavior is based on calling another program, maybe built into the OS, maybe not.
this behavior is hated by some antivirus software, and might cause some problems.
another thing is, it looks to me like OS depending, the same phrase can have multiple meanings on different operating systems.
some command defined in windows, isn't even defined in Linux.
EDIT - i forgot to add the code for pause, lol :).
i published the code into a news post, but looks like the admins might have deleted it for unknown purpose.