Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1567908
  • 博文数量: 354
  • 博客积分: 8137
  • 博客等级: 中将
  • 技术积分: 5137
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-26 15:40
文章分类

全部博文(354)

文章存档

2010年(300)

2009年(54)

分类: C/C++

2010-06-20 06:15:27

两种情况考虑,一种情况是用IDE来运行C程序,另一种情况是用来运行C++程序。
用来运行C程序的话,需要程序执行结束之前执行语句
system("pause");
程序实例:
//: main.c
#include
 
int main() {
    printf("An simple example.\n");
   
    system("pause");
    return 0;
}
 
用来运行C++程序的话,也是一样的道理需要在程序执行结束之前执行语句
system("pause");

但是system()函数在stdlib.h头文件中定义,因此需要include这个头文件(不知道是不是IDE中是否在编译C程序时自动 include了这个头文件。)。
程序实例:
//: main.cpp
#include
#include
 
int main() {
    printf("An simple example.\n");
   
    system("pause");
    return 0;
}
因此,最好的写法还是无论是C程序还是C++程序都先include头文件stdlib.h,再在程序执行结束之前加入代码
system("pause");
阅读(3468) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~