Q:

Decimal to Binary Signed in C++

This is what I have:
string decimal_to_binary(int n){
string result = "";
while(n > 0){
    result = string(1, (char) (n%2 + 48)) + result;
    n = n/2;
}
return result; }

This works, but it doesn't work if I put a negative number, any help?

A:

Well I would recommend calling a separate function for negative numbers. Given that, for example, -1 and 255 will both return 11111111. Converting from the positive to the negative would be easiest instead of changing the logic entirely to handle both. 
Going from the positive binary to the negative is just running XOR and adding 1.
You can modify your code like this for a quick fix.
string decimal_to_binary(int n){
    if (n<0){ // check if negative and alter the number
        n = 256 + n;
    }
    string result = "";
    while(n > 0){
        result = string(1, (char) (n%2 + 48)) + result;
        n = n/2;
    }
    return result;
}

