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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
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());
int ID, hpw;
double salary;
while(true)
{
if(infile.eof())
{
break;
}
getline(infile, temp, ';');
// istringstream buffer1(temp);
// buffer1 >> ID;
istringstream(temp) >> ID;
a.ID = ID;
getline(infile, temp, ';');
a.fname = temp;
getline(infile, temp, ';');
a.lname = temp;
getline(infile, temp, ';');
// istringstream buffer2(temp);
// buffer2 >> salary;
istringstream(temp) >> salary;
a.salary = salary;
getline(infile, temp, ';');
// istringstream buffer3(temp);
// buffer3 >> hpw;
istringstream(temp) >> hpw;
a.hpw = hpw;
getline(infile, temp, '\n');
a.work = temp;
ListEmployee.push_back(a);
/*
Kept getting a "stoi is not a member of std"
*/
// 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;
}
}
|