system(“pause”); - Why is it wrong?

前端 未结 13 2326
轻奢々
轻奢々 2020-11-21 07:39

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

The command, system(\"pause\"); is taught to new programmers as a way to pause a program and wait for

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 07:39

    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.

    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.

提交回复
热议问题