Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
need advise in reading binary file
i am trying to read a binary file (input.bin)that contains 2 characters
1 fstream f;
2 char uc;
3 char *uc2;
4 std::ostringstream ost;
8 f.open("c:/input.bin", ios::in|ios::binary);
9 f.read((char *)&uc, 2);
13 ost << uc << *(uc2++);
16 cout << " output "<< ost.str() <<"
Why do I need to increment the uc2 twice (at Line 11, Line 13), before I can read in the 2nd character in my binary file correctly?
Is there a better way to improve the code?
I am trying to do print out the entire "uc" string in 1 command.
printf(" %s", uc);
(ideal output) UP
If not possible what is another better method than the above code.
0 · ·