我是C+=的初学者,今天刚给我的Hello写信。
#include <iostream>
int main(){
double x = 6.25;
x = sqrt(x);
std::cout << x;
return 0;
}这在Visual中有效,没有错误消息,同时添加:
#include <cmath> 效果也很好。
但是,使用GCC编译器联机时,前面的代码将返回
main.cpp: In function 'int main()':
main.cpp:5:12: error: 'sqrt' was
not declared in this scope x = sqrt(x);
^帮帮忙,谢谢。
发布于 2014-01-23 14:50:40
没有自动包含行为。通过包含<iostream>,您就间接地包含了<cmath>。
这正是微软实现C++标准库的方式,他们希望在其中使用一些<cmath>函数,因此他们需要将其包含在头文件中。
我建议你读一下这个文章。
https://stackoverflow.com/questions/21311247
复制相似问题