我搞不懂为什么这段代码不包含
"#include <cmath>"下面是我的代码,没有它它也能工作。
// PowerApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << pow(2, 3) << "\n";
return 0;
}我提到了What is the C++ function to raise a number to a power?,这再次证实了我们需要它。
我检查了pow的定义,它是<cmath>的一部分,但只要我包含<iostream>,它就能正常工作
发布于 2018-07-23 12:27:43
首先,任何以.h结尾的C++系统头文件都是来自20年前C++标准化之前的文件,它们已经过时,永远不应该使用。
头文件可能包括其他头文件,但标准中没有任何要求。如果您需要数学函数,那么显式地包含<cmath>。
如果您想知道哪些函数和/或类需要哪些头文件,我推荐参考站点like this one。
https://stackoverflow.com/questions/51471545
复制相似问题