File Stream

Status
Not open for further replies.

Thunder

Wise, Aged Ars Veteran
108
I am making a program that reads a list of numbers from one file and prints them to another file and so far I have this : #include <fstream.h>


int main ()
{
//int count =0;
ifstream fsin;
ofstream fsout;

fsin.open("parts.cpp");
fsout.open("total.dat");
if (!fsin )
{
cerr << "Error opening parts file" << endl;
}



while(!fsin.open("parts.cpp").eof)
//count += 1;

fsin.close();
fsout.close();

return 0;
}
How do I get the data from the data.cpp file to show up in the total.dat file? and get it to print in columns?
 
Code:
 while(!fsin.open("parts.cpp").eof)
For a start this usually looks more like
Code:
while(fsin)
{
    string aLine;
    getline(fsin, aLine);
    // do something with the line (whatever you like)
    fsout << "whatever" << someVariableFromYourProcessing << endl;
}
What you want to do seems to involve some parsing, and probably a good deal of formatting. It would help if you could tell us what's the format of the input file (a short sample would be great) and what you want the output to look like.

Edit: Some general steps inside the loop would be:
1) retrieve your data from the input file (get numbers from the string, whatever)
2) compute what you need
3) write the results to the output file
 
Status
Not open for further replies.