C++ 错误:';战俘';未在此范围中声明 #包括 使用名称空间std; int main() { int x; cout x; cout
在C++ 错误:';战俘';未在此范围中声明 #包括 使用名称空间std; int main() { int x; cout x; cout,c++,C++,在cmath中定义,因此您需要包括cmath: #include <iostream> using namespace std; int main() { int x; cout << "How many rows would you like? " << endl; cin >> x; cout << endl; cout << "Number| Power 1| Power
cmath
中定义,因此您需要包括cmath
:
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "How many rows would you like? " << endl;
cin >> x;
cout << endl;
cout << "Number| Power 1| Power 2| Power 3| Power 4| Power 5" << endl;
for (int j=0; j<=x; j++)
{
cout << j << "\t" << j << "\t" << pow(j,2) << "\t" << pow(j,3) <<
"\t" << pow(j,4) << "\t" << pow(j,5) << endl;
}
return 0;
}
#包括
#include/正如错误消息告诉您的那样,编译器不知道在哪里可以找到pow()
在使用非自己编写的函数时,需要包含适当的头文件。就像在std::cout
和std::cin
中包含iostream
一样,在std::pow
中需要包含cmath
只需将#include
添加到程序的开头。不要标记垃圾邮件。对不起,我不知道,我是新来的。我肯定不会再添加了。您需要#将包含在“新”代码中这真的不是借口。你很清楚这个问题与Java或C无关。我认为同样的问题在后一种语言中也可能发生。@Pablo谢谢,我已经编辑过了。我想我太累了^^
#include <iostream>
#include <cmath> // <-- include cmath here
using namespace std;
int main()
{
int x;
cout << "How many rows would you like? " << endl;
cin >> x;
cout << endl;
cout << "Number| Power 1| Power 2| Power 3| Power 4| Power 5" << endl;
for (int j=0; j<=x; j++)
{
cout << j << "\t" << j << "\t" << pow(j,2) << "\t" << pow(j,3) <<
"\t" << pow(j,4) << "\t" << pow(j,5) << endl;
}
return 0;
}