gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:56:55 24 4
gpt4 key购买 nike

每次用户在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com