I wonder why this program does not do any changes to the text file that I am trying to modify.
Scenario: My program uses the Fstream header file, I declared infile as IFSTREAM and outfile as OFSTREAM. I simply want to transfer data from infile to outfile. The data is as follows;
Adam Larson 89 90
This data is saved in a text file manually created with Notepad. Furthermore, I also want to add the average of 89 and 90 into the outfile target file however, it doesn't do it. it does nothing at all. I also observed that there seems to be no data extracted at all using the infile variabe so nothing is being copied into the output file. here is my code;
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream infile;
ofstream outfile;
infile.open("C:\Projects\C++\infile.txt");
outfile.open("C:\Projects\C++\outfile.txt");
string fname, lname;
int mathgrade, sciGrade;
double average;
//get data from Input file
cout << "This program creates a copy of a student data file with average\n";
infile >> fname >> lname;
infile >> mathgrade >> sciGrade;
average = (mathgrade + sciGrade) / 2;
//copy data into Output file
outfile << fname << " " << lname << " " << mathgrade << " " << sciGrade << " " << endl << "Average: " << average << endl;
outfile.close();
infile.close();
cout << "Done processing...\nCheck thie file for output: C:\Projects\C++\outfile.txt\n";
system("pause");
return 0;
}
This program does not have any errors but does not do anything either.
What am I missing?