c++ - 如何在 C++ 中检查操作系统是 Windows 还是 Debian?

标签 c++ windows linux

每次用户在 C++ 中进行输入时,我都想清除控制台屏幕。

我正在考虑使用系统命令。对于 Windows,它是“cls”。对于 Linux,它是“清晰的”。有没有办法检查哪个系统在 C++ 中使用适当的命令?

谢谢。

最佳答案

有一个技巧解决方案:

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

对于 Unix,它可以正常工作。对于 Windows,它会提示类似

的错误

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

虽然它现在会被“cls”清除。所以在命令提示符窗口中,它不会留下任何痕迹。 :D

关于c++ - 如何在 C++ 中检查操作系统是 Windows 还是 Debian?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2557760/

相关文章:

c++ - 使用A4音调扩展.WAV文件

c++ - 为什么删除移动构造函数后我的对象没有被复制?

windows - 尝试在 Firefox 上运行 js - 它在 Linux 上运行良好,但在 Windows 上不行

linux - 使用 pentaho 作业加密密码并存储在文件中

Linux 出包率

java - C/C++ 等价于 java Integer.toHexString

c++ - const char* 和 char* 的参数类型无效

windows - sublime text 2 控制台仅显示 gruntjs 输出的第一行

php - UTF-8贯穿始终

linux - linux 无法添加环境变量