Hello, i have a project which requires that i work with three files.
two files are text and one file is .dat
Currently I have been successful at creating the dat and one of the texts. The project is a bit menu driven and is about stocks, when the program starts, if there is no dat file it creates one, however this dat will be empty, so the data is stored in a text and the program gives the option to the user to import a file. The text that i mentioned about outputs any changes made to the dat.

Anyways, the text that i need to import is made in the following format without any headers, it is just numbers:
(the file has not been made)
stocknumber (100-999)Low(lowest price from last year), High(from last year), Current Price, Change since last trading day.
Can anyone come up with a loop to read the the data from the file and read it into the dat?

Don't ask for code, Try it and don't be lazy, And if you got stuck in something we are here to help you, but just give it a try. Get a pen and a paper and try to analyze what will the program do, and then decide how you will implement this logically, then if you got any problems ask us.

Can anyone come up with a loop to read the the data from the file and read it into the dat?

Yes we can. But it's your task, not ours. You come up with the loop and if it doesn't work, we can help you fix it. But we aren't going to write it for you.

I heard that reading a text file requires something like fields, for example in this case it would be the stock #, price, change, low and high, so i will need a total of 4 fields.
I have an idea of doing something like:

ifstream inImportStock("stockfile.txt", ios::in);

if (!inImportStock)
  cerr << "File Unable to Open" << endl;
while(inImportStock && !inImportStock.eof())
 //This part is something im having trouble with
 low = 
 high = 
 change = 
 price = 

if (inImportStock.eof())
cout << "Done!" << endl;

You have to look at your input file and figure out how to read each field. Since you know how to open a file, look up how to read the file. It must be within the next couple pages of your book.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.