关键词搜索

源码搜索 ×
×

main函数中的argc和argv是什么意思?

发布2012-11-29浏览13811次

详情内容

      先看程序:

  1. #include<iostream>
  2. using namespace std;
  3. int main(int argc, char *argv[])
  4. {
  5. cout << argc << endl;
  6. cout << argv[0] << endl;
  7. return 0;
  8. }


      结果为:

1
C:\Documents and Settings\Administrator\桌面\cpp\Debug\test.exe

      在VC6.0中选择“工程”,设置,然后按下面的图片填上相关信息:

 

       此时,将程序改为:

  1. #include<iostream>
  2. using namespace std;
  3. int main(int argc, char *argv[])
  4. {
  5. cout << argc << endl;
  6. cout << argv[0] << endl;
  7. cout << argv[1] << endl;
  8. cout << argv[2] << endl;
  9. cout << argv[3] << endl;
  10. return 0;
  11. }


       结果为:

4
C:\Documents and Settings\Administrator\桌面\cpp\Debug\test.exe
a
b
c


 

       如果程序要读取某文件的信息,而该文件的名称不是在程序中给定,而是由用户确定,那么给main传参数就是一个很好的方法.

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载