这节课在讲什么东西。。。
001
/*
Description: main函数:处理命令行选项
*/
#include<iostream>
#include<stdlib.h>
using namespace std;
// 命令行选项
// 个数 字符串数组,每一个选项是一个字符串
int main(int argc,char **argv)
{
cout<<argv[0]<<endl;//arr[0]不是命令行选项
cout<<argv[1]<<endl;
cout<<argv[2]<<endl;
for(int i = 0;i<argc;++i)
{
cout<<argv[i]<<endl;
}
int start,end,step;
start = atoi(argv[1]);
end = atoi(argv[2]);
step = atoi(argv[3]);
// [Error] 'atoi' was not declared in this scope
for(int k = start;k<end;k+=step)
cout<<k<<endl;
return 0;
}
002
#include<iostream>
#include<stdlib.h>
using namespace std;
// char** argv
int main(int argc,char* argv[])
{
if(argc != 3)
{
cout<<"you sould use three arguments!"<<endl;
return -1;
}
cout<<"这两个数的和是:"
<<atof(argv[1])+atof(argv[2])<<endl;
return 0;
}