system() 有什么不好?

编程入门 行业动态 更新时间:2024-10-28 00:29:51
本文介绍了system() 有什么不好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-26 00:44:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126798.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   不好   system

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!