How to check if Windows or Debian OS is in C ++?

I want to clear the console screen every time a user makes input in C ++.

I am considering using a system command. For Windows, this is "cls". For Linux, this is "understandable." Is there a way to check which system to use the appropriate command in C ++?

Thank.

+3
source share
4 answers

There is a solution for tricks:

if (system("clear"))
  system("cls");

For Unix, it works fine. On Windows, this will result in an error, for example

'clear' is not recognized as an internal or external command, operating program, or batch file.

While it will be cleared right now, "cls". Therefore, in the command prompt window it will not leave any track .: D

+5

, ++.

Windows WINDOWS linux, LINUX; (, Visual Studio WIN32).

+4

You can also use C Preprocessor - conditional syntax in C ++.

#ifdef linux
    //clear
#else
    //cls
#endif
+1
source

Source: https://habr.com/ru/post/1739408/


All Articles