read binary file one line at a time

hello,
Newbie trying to teach myself c++. I am trying to read from a binary file written by fortran.
I have two issues that make me want to read line by line, 1) the binary file is huge and 2) I only want specific parts of the data. (And well a 3rd problem - it was written by fortran so that will bring about a host of other issues, but anyway....)
Thus I would like to read the file one line at a time, look at the line, and then make a decision as to what to do next. I do not want to ingest it all at once. Is getline the way to go?
I have a how-to book and I have searched on this website, but the lore seems to assume a binary file is all the same datatype and that one wants to ingest it in one big go.

My binary file begins with a main header. Right now, I just want to open the file, read in the main header line by line, and spit it out to the screen. I am reading from the file, but I cannot see a result.
I declared a character buffer of an arbitrary [180] just to see if I could ingest anything at all and I repeat the below action several times but I get no result.

Here is what I have:
NOTE: the code compiles and runs, but nothing prints to the screen except newlines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
     
     std::ifstream fileInput;
     // here we assoc stream class with a physical object, namely a file
     // and we open it in mode binary
     fileInput.open(filenamein.c_str(),std::ios::binary);

     //check that the file was opened before utilizing it
     if (fileInput.is_open()) {

        std::cout << "yay! it opened.\n";
        std::string FTI;
     // read off the header information
        char buff[180];
        fileInput.getline(buff,sizeof(buff));
        fileInput >> FTI;
        std::cout << FTI << "\n";
        (repeat above 3 lines several times to try and get something)
Don't use fileInput.getline()...just use the normal getline(), and put it directly into the string, this avoids the problems associated with char*.
Thanks much, firedraco.
that worked - I can see my header lines. Unfortunately they are embedded in a bunch of garbage. I guess what is a line in a fortran file is not recognizable as the same line in a non-fortran binary file, because a whole lot more is being read in. At this point I am thinking the best option may be to step out to a fortran subroutine, read the data, then step back into the C++ program. Time for a web search...
thanks again!
Topic archived. No new replies allowed.