#include <iostream>
#include <math.h>
#include "stdafx.h"
using namespace std;
int main()
{
float a, b;
cout << "Enter The Number: ";
cin >> a;
b = sqrt(a);
cout << "The Square Root of The Number Is: " << b;
return 0;
}
编译器给出错误:
consoleapplication1.cpp(10): error C2065: 'cout': undeclared identifier
consoleapplication1.cpp(11): error C2065: 'cin': undeclared identifier
consoleapplication1.cpp(12): error C3861: 'sqrt': identifier not found
consoleapplication1.cpp(13): error C2065: 'cout': undeclared identifier
请告诉我错误以及为什么我包含“stdafx.h”以及为什么它在引号中?使用 Visual Studio 2015。级别:初学者
最佳答案
只需将 #include "stdafx.h"
移动到文件顶部,您的代码就会编译。
stdafx.h 包含预编译头,如果你想删除它,你必须在项目属性中禁用它。
更好的选择是在 visual studio 中创建新项目时禁用它
文件 -> 新建项目 -> 选择你的设置并输入 OK -> 下一步 -> 这里取消选中“预编译头文件” -> 完成
关于c++ - 这段C++代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38944371/