问题描述
限时送ChatGPT账号..鉴于您正在构建一个 Windows 专属程序,为什么对 system()
的调用如此讨厌?自从我开始用 C++ 编程以来,不要接触系统"是我听过很多次的话.我温顺地遵守了这个原则,但这有什么不好?
Given that you're building a Windows - exclusive program, why are calls to system()
so hated? Ever since I started programming in C++, "don't touch system" was something I've heard an awful lot. I've obeyed that principle docilely but what's so bad about it?
推荐答案
您在系统调用中放置的内容取决于您将在其上运行程序的操作系统.所以它是完全不可移植的.此外,许多事情都可能出错,因为您只是向虚空发出命令,并希望一切顺利.错误处理(例如-您要运行的程序不存在,或PATH设置不正确,或您没有权限等)非常困难甚至不可能.
What you put inside the system call is dependent on the OS you will run the program on. So it's completely non-portable. Also, many things can go wrong, as you're just throwing a command into the void, and hope that everything will go fine. Error handling (for example - the program you want to run does not exist, or PATH is not set correctly, or you don't have permissions, etc.) is very hard or even impossible.
除此之外,正如大部分时间(真正大多数",例如 99.999%)的评论中所指出的,不需要使用 system
.
Beside this, as noted in the comments most of the time (really "most", like 99.999%) there is no need to use system
.
这篇关于system() 有什么不好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论