我需要得到一个参数并将其转换为int。这里是我的代码到目前为止:如何将命令行参数转换为int?
#include <iostream>
using namespace std;
int main(int argc,int argvx[]) {
int i=1;
int answer = 23;
int temp;
// decode arguments
if(argc < 2) {
printf("You must provide at least one argument\n");
exit(0);
}
// Convert it to an int here
}
我推荐反对atoi:“atoi()函数已被strtol()弃用,不应在新代码中使用。” – WhirlWind 2010-05-09 13:54:18
如何判断一个转换是否实际上是通过'atoi'进行的?这似乎是避免“atoi”给我的一个很好的理由。 – 2010-05-09 13:55:01
@WhirlWind不赞成由谁? – 2010-05-09 13:55:54