一个c ++程序在两个IDE中返回不同的结果 [英] a c++ program returns different results in two IDE

查看:70
本文介绍了一个c ++程序在两个IDE中返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CodeBlocks 中编写以下 c ++ 程序,结果为9183.再次在 Eclipse 中编写它,运行后,它返回9220.都使用 MinGW .正确的结果是9183.此代码有什么问题?谢谢.源代码:

I write the following c++ program in CodeBlocks, and the result was 9183. again I write it in Eclipse and after run, it returned 9220. Both use MinGW. The correct result is 9183. What's wrong with this code? Thanks. source code:

#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;
}

推荐答案

您可能会看到由于32位模式下的CodeBlocks编译和64位模式下的Eclipse编译而导致的精度错误:

You are probably seeing precision errors due to CodeBlocks compiling in 32-bit mode and Eclipse compiling in 64-bit mode:

$ g++ -m32 test.cpp
$ ./a.out
9183
$ g++ -m64 test.cpp
$ ./a.out
9220

这篇关于一个c ++程序在两个IDE中返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆