系统(“暂停”); - 为什么会出错? [英] system("pause"); - Why is it wrong?

查看:113
本文介绍了系统(“暂停”); - 为什么会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个我不太明白的问题:

Here's a question that I don't quite understand:

命令 system(pause); 被教给新程序员作为暂停程序并等待键盘输入继续的方法。然而,它似乎被许多老牌程序员皱眉了,因为不应该在不同程度上做。

The command, system("pause"); is taught to new programmers as a way to pause a program and wait for a keyboard input to continue. However, it seems to be frowned on by many veteran programmers as something that should not be done in varying degrees.

有些人说可以使用。有人说,只有当你被锁在你的房间,没有人在观看时才使用。有人说,他们会亲自来到你的房子,杀了你,如果你使用它。

Some people say it is fine to use. Some say it is only to be used when you are locked in your room and no one is watching. Some say that they will personally come to your house and kill you if you use it.

我,我是一个没有正式编程培训的新程序员。我使用它,因为我被教导使用它。我不明白的是,如果它不是要使用的东西,那么为什么我教会使用它?

I, myself am a new programmer with no formal programming training. I use it because I was taught to use it. What I don't understand is that if it is not something to be used, then why was I taught to use it? Or, on the flip side, is it really not that bad after all?

你对这个问题有什么想法?

What are your thoughts on this subject?

推荐答案

它是皱眉的,因为它是一个平台特定的黑客与实际学习编程无关,而是围绕IDE /操作系统的功能 - 控制台窗口从Visual Studio中启动的程序已经完成执行时关闭,因此新用户不会看到他的新程序的输出。

It's frowned upon because it's a platform-specific hack that has nothing to do with actually learning programming, but instead to get around a feature of the IDE/OS - the console window launched from Visual Studio closes when the program has finished execution, and so the new user doesn't get to see the output of his new program.

暂停)运行Windows命令行暂停程序,并等待它在继续执行程序之前终止 - 控制台窗口保持打开,因此您可以读取输出。

Bodging in System("pause") runs the Windows command-line "pause" program and waits for that to terminate before it continues execution of the program - the console window stays open so you can read the output.

一个更好的想法是在结束时放置一个断点并调试它,但这又有问题。

A better idea would be to put a breakpoint at the end and debug it, but that again has problems.

这篇关于系统(“暂停”); - 为什么会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆