Я получаю сообщение об ошибке, и не знаю почему, я очень новичок в С++, и если бы вы могли посмотреть на остальную часть моего кода, чтобы убедиться, что все в порядке, это было бы здорово.
Я получаю сообщение об ошибке в этих двух строках.
getline(in, e.first, ',');
getline(in, e.last, ',');
Он говорит, что класс Employee не имеет члена First, и я знаю, что это не в этой функции, как я могу это исправить?
Вот остальная часть моего кода.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Person {
string first;
string last;
};
struct Address {
string street;
string city;
string state;
string zipcode;
};
struct Employee {
Person name;
Address homeAddress;
int eid;
};
void readEmployee(istream& in, Employee& e);
void displayEmployee(ostream& out, const Employee& e);
int main(int argc, const char* argv[]) {
Employee e[50];
ifstream fin;
ofstream fout;
fin.open("employeesIn.txt");
if (!fin.is_open()) {
cerr << "Error opening employeesIn.txt for reading." << endl;
exit(1);
}
fout.open("employeesOut.txt");
if (!fout.is_open()) {
cerr << "Error opening employeesOut.txt for writing." << endl;
exit(1);
}
int EmployeePopulation = 0;
readEmployee(fin, e[EmployeePopulation]);
while (!fin.eof()) {
EmployeePopulation++;
readEmployee(fin, e[EmployeePopulation]);
}
fin.close();
for (int i = 0; i <= EmployeePopulation - 1; i++) {
displayEmployee(fout, e[i]);
}
fout.close();
cout << endl;
return 0;
}
void readEmployee(istream& in, Employee& e) {
string cidText;
if (getline(in, cidText, ',')) {
e.eid = stoi(cidText);
getline(in, e.first, ',');
getline(in, e.last, ',');
getline(in, e.homeAddress.street, ',');
getline(in, e.homeAddress.city, ',');
getline(in, e.homeAddress.state, ',');
string zipcodeText;
getline(in, zipcodeText, ',');
e.homeAddress.zipcode = stoi(zipcodeText);
}
}