c++ - 为什么我在终端中收到 cmath 错误?
问题描述
我在终端中编译我的代码时遇到了问题,特别是针对 cmath 的错误。
这是错误代码。
area_calculator.cpp:45: error: call of overloaded `pow(int&, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: error: candidates are: double pow(double, double)
/usr/include/g++/cmath:512: error: long double std::pow(long double, int)
/usr/include/g++/cmath:508: error: float std::pow(float, int)
/usr/include/g++/cmath:504: error: double std::pow(double,int)
/usr/include/g++/cmath:495: error: long double std::pow(long double, long double)
/usr/include/g++/cmath:486: error: float std::pow(float,float)
当我在 cpp.sh 中运行代码时,它运行良好,但编译后出现错误。
这是我的代码
#include <iomanip>
#include <iostream>
#include <cmath>
int main() {
int optionNumber;
int radius;
const double pi = 3.14159;
double circleArea;
int length, width;
double rectangleArea;
int base, height;
double triangleArea;
if (n == 1) {
std::cout << std::fixed;
std::cout << std::setprecision(2);
circleArea = pi * pow(radius, 2);
} else if (n == 2) {
std::cout << std::fixed;
std::cout << std::setprecision(2);
rectangleArea = length * width;
} else if (n == 3) {
std::cout << std::fixed;
std::cout << std::setprecision(2);
triangleArea = (base * height * 0.5);
}
}
当然,由于这是家庭作业,因此缺少一些代码,但我认为这应该会有所帮助。
提前致谢。
解决方案
推荐阅读
- sql - 关于正确数据结构的问题
- database - 对于 DML 操作中的错误记录,是否可以将错误记录到集合或临时表中?
- angular - 如何实现 Angular 的约定优于配置?
- c# - 如何从 C# 中的文本文件中读取特定行
- regex - 获取具有可变属性的标签之间的内容
- java - 如何在改造中从 json 对象键中删除空格?
- numpy-ndarray - 如何逐块循环ndarray
- symfony-security - Symfony 安全组件不记得会话
- node.js - Vue 定义 index.html 文件在哪里
- javascript - 如何修复javascript中的复制到剪贴板错误?