?? already submitted my answer but im confused

// Write a program that copies the data in the
// prelab input file to an output file "flux_capacitor"
// so that it is formatted the same in both files.
//
// Additionally add 30 to the year when you rewrite
// it to the output file to help Marty Mcfly get back to
// his proper time.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
// declaring variables
string firstName;
string lastName;
int year;

// declare input file stream variable and open file
ifstream fin;
fin.open("prelab_input.txt");

// Test to see if file correctly opened. If statements will
// be learned in the future. For now, don't worry about
// understanding this.
if (!fin)
{
cout << "ERROR - File failed to open. make sure that "
<< "the input file and this file are in the"
<< "same directory" << endl;
return -1; // Return statement will terminate the program. We do not want
// to continue if we do not have a valid input file.
}

// declare output file stream varaible and open file
ofstream fout;
fout.open("flux_capacitor.txt");


// ADD HERE write your code here





// closing files
fin.close();
fout.close();

return 0;
}
We are just as confused, and we sadly aren't from the future so we don't know how this confusion will be resolved. :(

Without seeing any actual file formatting, I would start by doing something like this with your streams
1
2
3
4
5
6
7
8
9
// put space-delimited data from fin to corresponding variables
fin >> firstName;
fin >> lastName;
fin >> year;

// put data from variables into fout
fout << firstName;
fout << lastName;
fout << year + 30;

I think we'll need to see some file formatting if you want any good help,

and you should show what you've tried yourself so far.


Last edited on
thanks!
Topic archived. No new replies allowed.