【发布时间】:2012-06-18 22:48:50
【问题描述】:
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char *argv[])
{
if (argc < 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);
return 0;
}
我收到以下错误
错误 1 错误 C2143:语法错误:缺少 ';'在“类型”之前
错误 2 错误 C2143:语法错误:缺少 ';'在“类型”之前出现错误 3 错误 C2065:“输入值”:未声明的标识符
错误 4 错误 C2065: 'outputValue' : 未声明的标识符
【问题讨论】:
-
为我编译。我认为代码不是一对一的翻译。
-
顺便说一句,如果在调用
atof之后inputValue是0,那么用户是否输入了0或无效的内容? (提示:你不知道) -
Visual C++ 会根据扩展名(.c 或 .cpp)自动选择 C 或 C++。如果将其编译为 C,那么这里有许多副本可以回答您的问题:stackoverflow.com/questions/8496853/…
-
@Mysticial Sounds 发现了我
标签: c++ visual-studio-2010 visual-c++