我想接受一个命令行参数(它将是一个大于零的整数)并将其用作函数中的整数参数(以决定使用函数的哪一部分)。
double func(double x, double y, double z, int n) {
if (n==1) { return 1; }
if (n==2) { return 2; }
// etc
}
int main (int argc, char *argv[]) {
int n = argv[1];
// etc, later I call func(x,y,z,n) with this definition of n
}
当我尝试编译时,我收到一些警告:
warning: invalid conversion from ‘char*’ to ‘int’
warning: initializing argument 4 of ‘double func(double, double, double, int)’
我想我明白它为什么会发生,我只是不知道如何解决它。到目前为止,我发现谷歌搜索没有任何帮助。我是 C++ 的新手,任何能指引我正确方向的信息都会很棒。感谢您的时间。