我已经为我的班级写了这个程序.我发现它使用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)