I need to prompt the user for a txt file and display what the text in it. Our example is
January
Fishing line
132 spools 24 spools
Fish hooks
97 packages 45 packages
Sinkers
123 packages 37 packages
Fish nets
12 ea. 5 ea.
Tackle box
75 ea. 15 ea.
Fishing poles
135 ea. 18 ea.
The first line of the data file contains the month for which the report is being generated.
Then follows the description of a store item on the next line. Then follows how much inventory was present at the start of the month along with the quantity description.
Then follows how many of these items where sold during the month along with the quantity description. Then make it display like this
MONTH: January
ITEM BEGIN QTY UNITS SOLD ENDING QTY %SOLD
-------------- --------- ---------- ---------- -----
Fishing line 132 spools 24 108 18.18
Fish hooks 97 packages 45 52 46.39
Sinkers 123 packages 37 86 30.08
Fish nets 12 ea. 5 7 41.67
I can do the calculations and everything but im so confused on how to read the info from a file this is what i have so far and im totally confused on how to read each part from the file and then assign it to a variable.
This is what i got so far:
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#define cls system("cls")
using namespace std;
string getInputFileName();
int main ()
{
ifstream inFile;
string fileName;
fileName = getInputFileName();
inFile.open(fileName.c_str());
if (!inFile)
{
cerr << "Unable to open file " << fileName << endl;
exit(1);
}
inFile.close();
return 0;
}
string getInputFileName()
{
string fName;
cout << "Please enter the fully qualified name of the " << endl
<< "input text file (i.e. including the path): ";
cin >> fName;
cout << endl;
return fName;
}
after i know how to read in the file i can do the rest, i just need some help or a hint on how to do that! Thank you.