I'm given a string that is of binary 1's and 0's and I'm trying to make a function that is able to set the bits to the location that is specified.

If 35 represented in 100011

If I wanted to set the 3rd bit to a 1,

It would look like 100111

Similiarly to 0's as well.

I've found that my function will set it, but then it truncates the values or does something funny.

Code:
int setOne(string value, int position)
{
        int length = value.length();
        int temp;
        string t = value;

        value[length-(position+1)] = '1';

        temp = atoi(t.c_str());
        cout << temp << "\n";
        return temp;
}