Avoid Using The “system("pause")” !
来源:互联网 发布:网页翻译软件 编辑:程序博客网 时间:2024/06/05 02:08
About system("pause")
I've never understood why system("PAUSE") is so popular. Sure it will pause a program before it exits. This pause is very useful when your IDE won't wait as you test a program and as soon as the program finished the window closes taking all your data with it.
But using system("PAUSE") is like burning your furniture for heat when you have a perfectly good thermostat on the wall.
Many people, instructors included, for some inexplicable reason think that making a call to the operating system and running a system command to temporarily halt a program is a good thing. Where they get this idea is beyond me. Reasons:
It's not portable. This works only on systems that have the PAUSE command at the system level, like DOS or Windows. But not Linux and most others...
It's a very expensive and resource heavy function call.
It's like using a bulldozer to open your front door. It works, but the key is cleaner, easier, cheaper. What system() does is:suspend your program
call the operating system
open an operating system shell (relaunches the O/S in a sub-process)
the O/S must now find the PAUSE command
allocate the memory to execute the command
execute the command and wait for a keystroke
deallocate the memory
exit the OS
resume your program
There are much cleaner ways included in the language itself that make all this unnessesary.
You must include a header you probably don't need: stdlib.h or cstdlib
It's a bad habit you'll have to break eventually anyway.
Instead, use the functions that are defined natively in C/C++ already. So what is it you're trying to do? Wait for a key to be pressed? Fine -- that's called input. So in C, usegetchar() instead. In C++, how about cin.get()? All you have to do is press RETURNand your program continues.
- Avoid Using The “system("pause")” !
- system("Pause")
- system("pause")
- system("pause");
- system("pause");
- system pause
- system("pause")
- system(“PAUSE”)
- system("pause")
- system("pause")
- Using the script hotswapping system
- 如何隐藏system("pause")
- system("pause")详解
- system("pause") 和getchar()
- 关于system("pause")
- C system("PAUSE") 小议
- C++中的system("pause");
- system("Pause")你会用吗
- IOS之sha加密、md5常规加密、md5二次加密详解及示例程序
- PHP定时执行的三种方式实现
- Oracle 的时区设置
- 浅谈算法和数据结构: 七 二叉查找树
- Qt 进程通信QSharedMemory
- Avoid Using The “system("pause")” !
- QT5入门之7 - 修改程序图标
- centos 6-7的epel源配置
- 最糟心的Linux密码问题!!!
- 11.Python标准库_多进程探索 (multiprocessing包)
- Java中ModelAndView是做什么的?
- Adobe Acrobat XI pro虚拟打印机的安装教程(附激活)
- IOS单例模式及单例模式的优缺点
- MAC版 xampp 设置xdebug支持