Creating 2 output files from the data of one input file

Hi,

I have a file with some car information in it. We'll call it cars.dat. I'd like to be able to use the input from that file to create 2 other files called Over30.dat and Under30.dat. In each of these new files, I will extract data from the original and put it into the appropriate one. So say I had all cars that got >= 30 MPG into the Over30.dat, and < 30 into the Under30.dat.

How would I go about doing this?
open all files,
until you reach the end of cars.dat
read all data associated with one car,
compare that car's MPG to 30
and write all the data to either over30.dat or under30.dat
close all files

I suggest you make a car struct unless your cars have only one parameter.

http://www.cplusplus.com/doc/tutorial/files/
see binary files
Awesome!! Got it. Thanks! :)
Topic archived. No new replies allowed.