read from a file then output to another file, very basic!.:Resolved:.
Hello everyone!! I have no Idea what I did wrong in the following program, it simply reads data from a file called test.txt located at C:. The data in the test.txt file is the following:
C 87 89 65 37 98 and it should modify the data and output the data to testavg.out alot located on the C:
here's my code:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main(void)
{
int t1,t2,t3,t4,t5;
double average;
ifstream inFile;
ofstream outFile;
char studentId;
inFile.open("c:test.txt");
outFile.open("c:testavg.txt");
outFile << fixed << showpoint;
outFile << setprecision(2);
cout <<"Processing Data" << endl;
inFile >> studentId;
outFile<<"Student ID: " << studentId << endl;
inFile >> t1 >> t2 >> t3 >> t4 >> t5;
outFile<<"Test sources: " << setw(4) << t1
<< setw(4) << t2 << setw(4) << t3 << setw(4)
<< t4 << setw(4) << t5 << endl;
average = static_cast<double>(t1+t2+t3+t4+t5)/5.0;
outFile <<"Average test score: " << setw(6)
<< average << endl;
inFile.close();
outFile.close();
return 0;
}
I think it has somthing to do with the output file, because it doens't seem to create another file, also I thought it was odd when I typed in the following:
outFile.open() the member function open didn't pop up automatically like it did with inFile.open() and i'm using VC.net
Thanks for listening! :D