I have been playing with structures for the first time, quite simple really. But I seem to have trouble when I set a custom bit size for the data elements and the try to read directly into using standard ifstream class. The example code im puting has the file input commented out because it didn't work. The rest is there just as a test to see if my structure worked. Apparently I could just input an int and shift the bits but it would be for efficient to just do it directly.
So I get errors I couldnt get the sizeof() from a bitfield, but with or without sizeof i get errors that it cant match the type with the class (coulnt match unsigned, unsigned or even int). Ive tried casting it but it didnt work. do I need to use the -> operator to input to the sturcture?? I have no references that explain this. Please suggest the way to do it or if it is even possible.Code:#include<iostream.h> #include<fstream.h> void main(void) { char infile[256]; struct custom_size //in bits { unsigned one :1 ; unsigned two :2 ; unsigned three :3 ; unsigned four :4 ; unsigned five :5 ; unsigned six :6 ; unsigned seven :7 ; }; struct custom_size bits; int number = 6; //just to test how it was reading to struct. //cout << "Input a file name to read from: " //cin >> infile; //ifstream input_file(infile, ios::binary); //input_file.read(bits.one, sizeof(1)) bits.one = number; bits.two = number; bits.three = number; cout << bits.one << endl; cout << bits.two << endl; cout << bits.three << endl; };