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
|
void Open()
{
string rfile;
string temp;
cout << "Enter a file name to read from (be sure to add extension, \".txt\" to the end and use no spaces): ";
cin >> rfile;
if(fexists(rfile.c_str()))
{
ifstream infile;
infile.open(rfile.c_str());
while(true)
{
if(infile.eof())
{
break;
}
getline(infile, temp, ';');
a.ID = std::stoi(temp);
getline(infile, temp, ';');
a.fname = temp;
getline(infile, temp, ';');
a.lname = temp;
getline(infile, temp, ';');
a.salary = std::stod(temp);
getline(infile, temp, ';');
a.hpw = std::stoi(temp);
getline(infile, temp, '\n');
a.work = temp;
ListEmployee.push_back(a);
}
cout << "Data has been read." << endl;
infile.close();
return;
}
else
{
cout << "File does not exist. No data read from any file." << endl;
}
}
|