C++ main函数

 1 #include<iostream>
 2 using namespace std;
 3 class A {
 4 public:
 5     A(){
 6         cout<<"In constructor."<<endl;
 7     }
 8 };
 9 A a;
10 int main(){
11     cout<<"In main()."<<endl;
12 }
13 //输出:
14 In constructor.
15 In main.

1、main()函数被称为"入口函数".但是,main()函数不一定是程序中第一个被执行的函数.

 

1 #include<iostream>
2 using namespace std;
3 int main(int argc,char *argv[]){
4     if(argc>1){
5         cout<<"Hello,"<<argv[1]<<"!"<<endl;
6     }
7 }

2、main()函数可以带参数,以处理由用户输入的命令行参数。main()函数所带的参数有固定格式,argc代表参数的个数,

而argv数组中的每一个元素则是一个保存命令参数内容的字符串。

posted @ 2016-10-31 10:27  IT男汉  阅读(1314)  评论(0编辑  收藏  举报