I'm trying to do some I/O operations for some homework, but I'm stuck. I have to write a program that reads data from a text file, and store updated information in a [.dat] file. The text file reads as the following:
Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1
Last name, first name, current salary, and pay increase.
I have to read from the text file, write the [.dat] file with the last name, first name, and updated salary. Here is what I have so far, and I am completely lost. My professors husband died the first day of class, and we haven't went over I/O operations, but she still expects us to do the homework. How can I read from the text file, and write each line with the new updated salary?
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main() {
string line;
string firstName;
string lastName;
double currentSalary;
double increaseVar;
double updatedSalary;
ifstream inData;
ofstream outData;
inData.open("Ch3_Ex8Data.txt");
outData.open("Ch3_Ex8Output.dat");
if(inData.is_open()) {
while(!inData.eof()) {
inData >> lastName >> firstName >> currentSalary >> increaseVar >> updatedSalary;
getline(inData, line);
}
inData.close();
outData.close();
}
return 0;
}


Sign In
Create Account


Back to top









