Mar 6, 2016 at 4:33am UTC
Just wanna ask how to read a file from a .txt in this case you encode the list(employee name, employee number, tax ) directly to notepad. I only know how to read a file when you input it in dev c++ program. Thanks for the answer
Last edited on Mar 6, 2016 at 5:00am UTC
Mar 6, 2016 at 6:01am UTC
is the file written using objects or just data is present in it?
it depends...
Mar 6, 2016 at 7:55am UTC
THIS IS AN EXAMPLE THAT I NEED TO READ FROM .txt:
Employee No. Earning Code Amount
EMP0024 OT1 815.33
EMP0024 TXR 9244.00
EMP0021 TXR 14325.20
EMP0030 OT1 2300.00
EMP0030 OT4 4475.25
EMP0030 TXR 16375.12
EMP0044 TXR 15245.44
Mar 6, 2016 at 1:34pm UTC
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(void)
{
fstream src("Data.txt");
if (!src)
{
cerr << "\aFILE ERROR";
exit(EXIT_FAILURE);
}
//skip first line
string dummy;
getline(src, dummy);
//read to data
string name, number;
double tax;
while(src >> name >> number >> tax)
{
cout << "Name: " << name << "\tNumber: " << number << "\tTax: " << tax << "\n";
}
system("pause");
return EXIT_SUCCESS;
}