Trying to read a line of records from a file?

Here is my code:

#include <string>
#include <fstream.h>
#include <windows.h>

using std::string;

void main()

      ofstream out;
      ifstream in;
      string sBuff; "btnbad.asc", ios::in, filebuf::sh_read ); "btnbad.txt", ios::out, filebuf::sh_write );

      while( in.eof() == false )

            // Code that reads in the line of records

            // Writes to output file
            out.write( sBuff.c_str(), lstrlen( sBuff.c_str() ));



I thinkg its but not quite sure how to use it.  I dont want to read a character at a time but instead a line of records which then goes to the next line, etc.  Do I also need something to move the pointer to the next record on the next row?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What is the format of the file.  is it binary?  is it ASCII?  What is stored in each record?  how are things delimited?

Assuming the data is stored in ASCII. You can use the >> operator to read the data, like

int x;
double y;

in >> x; // reads the integer.
in >> y; // reads the double.

Does that help?

To move to the next line, you can use

eric07Author Commented:
I'm not rejecting your answer b/c I think its wrong b/c I dont know, but b/c I want to explain my question more clearly.  Here is the records in the file (btnbad.asc) that I would read( all in ASCII):


I would like to read in a line of record one at a time b/c somewhere in the program I will have to break it apart for formatting later on.  And that is why I'm trying to figure out how to use the read and write, etc.

I'm use to using CStdio in MFC but that doesnt work for ATL.  I do have another question and that is I'm also use to using fopen, fclose,  fwrite, etc. And I wonder is there a penalty for using C functions in an ATL based project.  I've read that bypassing C functions the atl component is allot smaller and more robust.

eric07Author Commented:
One more thing and that is I know that what I posted is not an ATL program.  I wanted to just figure out how to use file io using C++ then I was going to add it in my ATL project.
You don't need to reject an answer if you just want more clarification from the expert.  Reject an answer only if it becomes apparent that the expert cannot help you.

All of this information woyuld have been good to knwo before!

I would use getline() to read a single line into an STL string.  Then I would sub-string this string into strings that contain each individual field.  Tnen convert those fields to the final necessary data types.  

example follows.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Say for example the first 3 characters form a string that represent an integer, and the next 5 a string that represents a double you would do
string Lin;

string Fld1 = Lin.substr(0,2);
string Fld2 = Lin.substr(2,3);

int x;
double y;

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.