Results 1 to 4 of 4

Thread: read from a file then output to another file, very basic!.:Resolved:.

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Question 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!
    Last edited by voidflux; Jul 23rd, 2003 at 10:42 PM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width