I am a newbie to programming learning from Malik's Book C++ . My issue is with how to open files from my mac, the book uses examples and programs from Windows PC, no good for me. So far i have had no problems using C++ on Xcode. I am stumped on the language for inputing/outputting a file. I am not even exactly sure what question to ask.I copied the program from the book and pasted it here, as it states my confusion is how to format the file after .open. I am not even sure, can any file be accessed for this process? I just created a simple word doc but doesnt work. Any help would be appreciated, searched the net for solutions
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
ifstream inFile;
ofstream outFile;
double test1, test2, test3, test4, test5;
double average;
string firstName;
string lastName;
inFile.open("confused right here");
outFile.open("confused right here");
outFile << fixed << showpoint;
outFile << setprecision(2);
cout << "Processing data" << endl;
inFile >> firstName >> lastName;
outFile << "Student Name: " << firstName
<< " " << lastName << endl;
inFile >> test1 >> test2 >> test3
>> test4 >> test5;
outFile << "Test scores: " << setw(6) << test1
<< setw(6) << test2 << setw(6) << test3
<< setw(6) << test4 << setw(6) << test5
<< endl;
average = (test1 + test2 + test3 + test4 +test5) / 5.0;
outFile << "Average test score: " << setw(6)
<< average << endl;
inFile.close();
outFile.close();
return 0;
}
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
ifstream inFile;
ofstream outFile;
double test1, test2, test3, test4, test5;
double average;
string firstName;
string lastName;
inFile.open("confused right here");
outFile.open("confused right here");
outFile << fixed << showpoint;
outFile << setprecision(2);
cout << "Processing data" << endl;
inFile >> firstName >> lastName;
outFile << "Student Name: " << firstName
<< " " << lastName << endl;
inFile >> test1 >> test2 >> test3
>> test4 >> test5;
outFile << "Test scores: " << setw(6) << test1
<< setw(6) << test2 << setw(6) << test3
<< setw(6) << test4 << setw(6) << test5
<< endl;
average = (test1 + test2 + test3 + test4 +test5) / 5.0;
outFile << "Average test score: " << setw(6)
<< average << endl;
inFile.close();
outFile.close();
return 0;
}