我在CodeBlocks
中写了下面的c++
程序,结果是9183。我又在Eclipse
中写了,运行后返回 9220。两者都使用 MinGW
。正确的结果是 9183。这段代码有什么问题?
谢谢。
源代码:
#include <iostream>
#include <set>
#include <cmath>
int main()
{
using namespace std;
set<double> set_1;
for(int a = 2; a <= 100; a++)
{
for(int b = 2; b <= 100; b++)
{
set_1.insert(pow(double(a), b));
}
}
cout << set_1.size();
return 0;
}
最佳答案
由于 CodeBlocks 在 32 位模式下编译和 Eclipse 在 64 位模式下编译,您可能会看到精度错误:
$ g++ -m32 test.cpp
$ ./a.out
9183
$ g++ -m64 test.cpp
$ ./a.out
9220
关于c++ - 一个 c++ 程序在两个 IDE 中返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13635546/