reading a file from .txt

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
is the file written using objects or just data is present in it?
it depends...
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
#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;
}
Topic archived. No new replies allowed.