C++第1天:在C和C++里,要尽量避免使用 system("pause")
来源:互联网 发布:班加西事件知乎 编辑:程序博客网 时间:2024/05/22 10:42
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://amigniox.blogbus.com/logs/47563613.html
system("pause")
I've never understood why
But using
Many people, instructors included, for some inexplicable reasonthink that making a call to the operatingsystem
It's not portable. This works only onsystems
that havethe PAUSE commandat the system level, like DOS or Windows. But notLinux and most others... It's a very expensive and resource heavy function call.
It's like using a bulldozerto open your front door. It works, but the key is cleaner, easier,cheaper. Whatsystem() doesis: suspend your program
call the operating system
open an operating system shell (relaunches the O/S in asub-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 thatmake all this unnessesary.
You must include a header you probably don'tneed:
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 bepressed? Fine -- that's called
Note: the origin of the article isn't specified.
- C++第1天:在C和C++里,要尽量避免使用 system("pause")
- 在C和C++里,要尽量避免使用 system("pause")
- C system("PAUSE") 小议
- C语言中system("pause")是什么作用?
- 【C语言】【unix c】pause(2)使用
- C/C++内存泄露--工程中如何尽量避免
- 在C++Builder里使用AGG库
- 在codeblocks里使用hadoop c API
- 在CentOS里使用MySQL C API
- 在CentOS里使用MySQL C API
- C语言在VS里使用 inline
- 《Effective C++》:尽量用const和inline取代#define(1)
- 在C程序里和shell通信
- Effective Objective-C 2.0 第7条:在对象内部尽量访问实例变量
- system("pause")在使用freopen时失效
- [转贴]部分C语言库函数。为了避免重复造车轮,请尽量使用标准库提供的函数
- [转贴]部分C语言库函数。为了避免重复造车轮,请尽量使用标准库提供的函数
- C#里使用指针
- Extjs GridPanel用法详解
- 多个请求如何使用同一个 Servlet ?
- c# windows form 登录界面
- 字符串的空格替换算法
- POJ 1514 Metal Cutting
- C++第1天:在C和C++里,要尽量避免使用 system("pause")
- 牛客网-c++专项练习简单版
- Apache Shiro [urls]中配置的roles, perms, authc这样的filterChain的执行过程解析
- LeetCode 189. Rotate Array
- 在android里常用的默认开关的意义
- 双击退出
- 【u102】数列分段2
- shell脚本并发执行
- 1508-张晨曦总结《2016年-11月-28日》【连续38天总结】