Hello, my assignment is to make a program that takes a file as input, reads
the lines, and outputs them in a different format. It's something like:
lastName firstName creditHours inState
lastName firstName creditHours outState
etc. etc. etc;
We are told to make and output file that has
firstName lastName creditHours tuitionCost
etc. etc. etc.
This is what I made this evening but I have no idea how to use the getline()
function when I need to separate the strings like this. I haven't even gotten
to the part of the code where I have to worry about the output file, just clueless about how separate the strings and loop it for the next line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
ifstream Inputfile;
ofstream Outputfile;
int main(){
string first;
string last;
string credits;
string state;
string line;
string blank = " ";
Inputfile.open("input.dat");
if(Inputfile.is_open()){
for(int i = 0; i <= 4; i++){
do{
getline(cin, line);
if(i=1){
line = first;
}
else if(i=2){
line = last;
}
else if(i=3){
line = credits;
}
else{
line = state;
}
}while(!"\n");
}
}
|