#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;
}
編譯器給出了錯誤:這段C++代碼有什麼問題?
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.級別:初學者
您可以閱讀關於'stdafx.h' [here](http://stackoverflow.com/questions/4726155/whats-the-use-for-stdafx-h-in-visual-studio) – Rakete1111
TL; DR :將'#include「stdafx.h」'向上移動,所以它是源文件中的第一條(非註釋)行。 –
我相信您展示的錯誤不是唯一的錯誤。在此之前你應該有一個,關於預先編譯的頭文件「stdafx.h」沒有被包含在第一個。 –