0

I am trying to get information from a file. The content of the file is unknown. I am opening the file using a fstream object and storing each piece of data into a unsigned char . The size however of a char is 8 bits. But I need to get the data into 16 bits segments. I am using the bitset library to do this.

while(file>>test2)
{


    file>>test2;  
    bitset<16> foo(test2);

     cout<<foo<<endl;

}

first of all only gives me 8 bits of information using characters, if I use another data type the programs does not outputs anything. Is there another library that breaks a data type into bits?

Jongware
  • 22,200
  • 8
  • 54
  • 100
user3552926
  • 136
  • 3
  • `bitset` is not appropriate here. Try an `unsigned short`, which will be (at least) 16-bits. – ooga Apr 28 '14 at 19:42
  • Assuming `file` is a [C++ input stream](http://en.cppreference.com/w/cpp/io/basic_istream) object [`file.read()`](http://en.cppreference.com/w/cpp/io/basic_istream/read) is probably what you're looking for. – Captain Obvlious Apr 28 '14 at 19:42
  • @ooga I tried using short data type but the bitset object doesn't display anything. – user3552926 Apr 28 '14 at 21:06
  • @CaptainObvlious Thanks, I am trying the read() right now to see if I get something better! – user3552926 Apr 28 '14 at 21:07

0 Answers0