小编abr*_*dha的帖子

为什么这个C++程序在某些编译器中有效但在其他编译器中却不行?c ++编译器之间的主要区别是什么?

我已经为我的班级写了这个程序.我发现它使用GNU g ++编译器编译并运行得很好.我的教授从他的网站自动评分我们的程序,该网站使用Microsoft Visual Studio编译器,它会引发错误.我也在BSD clang编译器中尝试过这个程序,我得到了一个完全不同的错误.

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>

using namespace std;
double dec2Bin(int value, char binaryString[])
{
    int x = 1;
    string hold = "";
    while(x <= value){
        x *= 2;
    }
    x /= 2;

    while(x >= 1){
        //cout << x << " ";
        if(value > x){
            hold += "1";
            value -= x;
        }
        else if(value < x){
            hold += "0";
        }
        else if(value == x){
            hold += "1";
            value = 0;
            //return hold; …
Run Code Online (Sandbox Code Playgroud)

c++ g++ clang visual-c++ compiler-specific

-2
推荐指数
1
解决办法
213
查看次数

标签 统计

c++ ×1

clang ×1

compiler-specific ×1

g++ ×1

visual-c++ ×1