I want to convert a bitfield to a string. Visual Studio 2008 gives an invalid null pointer exception.
Maybe it has something to do with the size of the array. it must be 8 but the output says it is 4, but why?
class Converter
{
public:
string bitfieldToString (bool b_input[])
{
string c_conv;
int i;
for(i = 0; i < sizeof(b_input) ; i++)
{
if(b_input[i]=false){
c_conv.append("0");
}
else if (b_input[i]=true){
c_conv.append("1");
}
else c_conv = "Input is not a bitfield";break;
}
cout<<c_conv<<" "<< sizeof(b_input)<<endl;
return (0);
}
};
int main(void)
{
Converter converter;
bool b2[8] = {0,1,0,0,1,0,1,1};
converter.bitfieldToString(b2);
return (0);
}
Thank you! Now everything works as intended. and sorry for that dump question. I am new to C++.