I've been struggling with a problem for a while now. I'm trying to print out information which is contained in a binary file.

This what I get when I open it in notepad.

Marjorie Gestring   D201              ð¿      ð¿      ð¿      ð¿      ð¿        Patricia McCormick  D202              ð¿      ð¿      ð¿      ð¿      ð¿        Anna Andersson ick  D203              ð¿      ð¿      ð¿      ð¿      ð¿        Fanny Duracks  ick  D204              ð¿      ð¿      ð¿      ð¿      ð¿        Ulrika Knape   ick  D205              ð¿      ð¿      ð¿      ð¿      ð¿        Greta Johanson ick  D206              ð¿      ð¿      ð¿      ð¿      ð¿        Anna Lindberg  ick  D207              ð¿      ð¿      ð¿      ð¿      ð¿        Gunilla Rosenhoff   D208              ð¿      ð¿      ð¿      ð¿      ð¿        Kathy Peiss nhoff   D209              ð¿      ð¿      ð¿      ð¿      ð¿        Birgitta Conradson  D210              ð¿      ð¿      ð¿      ð¿      ð¿        Lisa Regnell adson  D211              ð¿      ð¿      ð¿      ð¿      ð¿        Leena Laine  adson  D212              ð¿      ð¿      ð¿      ð¿      ð¿        Paulina Suokas son  D213              ð¿      ð¿      ð¿      ð¿      ð¿        Gerda Meyerson son  D214              ð¿      ð¿      ð¿      ð¿      ð¿

I'm not trying to write anything complex right now. I just want to retrieve all the names and D-numbers for now.

What I wonder shouldn't this code print out every character it finds? If I want to get all the names and print it out nicely is it necessary to write a struct to contain the information?

char c;
    in.read( (char*)&c, sizeof(char) );
    while(!in.eof())  {

        in.read( (char*)&c, sizeof(char) );
        cout << c << endl;

9 Years
Discussion Span
Last Post by ganmo

It is binary file, i'm newbie in c++ sorry if I say something wrong.
Isn't there a way to interpret the binary file. And output only the strings I find in the file?

I've tried to fetch with this following code as well. Then it get the first name on the first loop, second loop I still get all scrap values that I don't want.

ifstream in("file.bin", ios::in | ios::binary);
string output;
in >> output
while(!in.eof())  {
    cout << output << endl;
    in >> output;

Hello, I solved the problem by myself now.

What I needed to know was what the size of the object was. And the rest solved automatically.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.