LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1148|回复: 5

新手

[复制链接]
发表于 2002-11-19 05:44:16 | 显示全部楼层 |阅读模式
有这样一段初学者的入门程序:
#include<iostream>

int main(int argc,char** argv)
{
  std::cout<<"how enn?"<<std::endl;
  return(0);
}

我有两个问题,主函数的第二个参数为什么要设成二级指针;
"std::"的作用是什么(是不是STANDARD域控制COUT的输出)。
手边资料有限,望有人指点。
发表于 2002-11-19 11:13:01 | 显示全部楼层
这是在命令行接受参数用的。argc表示参数个数,**argv是指向字符串数组的指针。如你用ls -l di*.c命令时,ls接受的argc为3(注意包括ls命令本身在内),argv[0]="ls"也就是命令自身,argv[1]=“-l",argv[2]=”di*.c",这样不管给命令有多少个参数,都能在程序中进行处理。在谭浩强编写的《C程序设计》里有详细论述,你可以找来看看。
发表于 2002-11-19 12:52:31 | 显示全部楼层
kj501:
这是在命令行接受参数用的。argc表示参数个数,**argv是指向字符串数组的指针。如你用ls -l di*.c命令时,ls接受的argc为3(注意包括ls命令本身在内),argv[0]="ls"也就是命令自身,argv[1]=“-l",argv[2]=”di*.c",这样不管给命令有多少个参数,都能在程序中进行处理。在谭浩强编写的《C程序设计》里有详细论述,你可以找来看看。
Good explanation.  However this is a C++ program, I would never recommend a C programming book for a C++ learner.
bluyo:
"std::"的作用是什么
``std::'' is specifying the namespace of the following objects.  As a beginner you needn't know much about namespace (as you needn't know much about standard library), just use it.  If you find it too tedious (maybe you need to write a lot of cout), just claim that you would like to use std namespace for the whole file, like:
  1. #include <iostream>
  2. using namespace std;

  3. int main()
  4. {
  5.     cout << "Hello world!" << endl;
  6. }
复制代码
Hope this helps.
 楼主| 发表于 2002-11-20 00:18:43 | 显示全部楼层
非常感谢不到一天就有这么详细的回复。手边实在没有合适的资料。能介绍几个c++网上学习的好地方吗(当然已经找到一个了^^)
发表于 2002-11-22 16:29:53 | 显示全部楼层
 楼主| 发表于 2002-11-23 03:26:31 | 显示全部楼层
恩~~很不错!各种文字对照,学起来真的很舒服。大恩不言谢:D
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表