初学C++ 遇到的第一个问题!
小代码:(用VS2008)
- C/C++ code
#include <iostream>#include <cmath.h>int main(){ using namespace std; double area; cout << "Enter the floor area,insquare feet,of your home:"; cin << area; double side; side = sqrt(area); cout << "that's the equivalent of a square << "feet to the side."<<endl; cout << "How fasciting!"<<endl; return 0;}报错:
命令行 正在创建临时文件“e:\TestStation\test3\test3\Debug\RSP00000D30885476.rsp”,其内容为
[
/Od /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ..\test.cpp
]
正在创建命令行“cl.exe @e:\TestStation\test3\test3\Debug\RSP00000D30885476.rsp /nologo /errorReport:prompt”
输出窗口 正在编译...
test.cpp
e:\teststation\test3\test.cpp(2) : fatal error C1083: 无法打开包括文件:“cmath.h”: No such file or directory
结果 生成日志保存在“file://e:\TestStation\test3\test3\Debug\BuildLog.htm”
test3 - 1 个错误,0 个警告
[解决办法]
#include <cmath.h> 改成 #include<cmath> 或#include<math.h> 前者是C++的写法后者是C语言的写法
[解决办法]
您cin的箭头写错了。
[解决办法]
#include <cmath.h>
把.h去掉,试试。#include <cmath.h>是C风格的。
[解决办法]
[解决办法]
cout << "that's the equivalent of a square
<< "feet to the side."<<endl; square后面掉了引号
[解决办法]
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
double area;
cout << "Enter the floor area,insquare feet,of your home:";
cin >> area;
double side;
side = sqrt(area);
cout << "that's the equivalent of a square"
<< "feet to the side."<<endl;
cout << "How fasciting!"<<endl;
return 0;
}
这是你写的代码 改过之后编译运行没有问题