错误:“pow”未在此范围内声明

She*_*ade -5 c++

#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;
}
Run Code Online (Sandbox Code Playgroud)

它会产生上述错误。我不确定出了什么问题,请告诉我。先感谢您。

Pab*_*blo 6

std::pow定义在 中cmath,因此您需要包括cmath

#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;
}
Run Code Online (Sandbox Code Playgroud)