I wondered can I overload operator>> in a way that it can work for user input and from reading file. When I need input from user std::cin>>CCity1;
and when I need from file std::ifstream ifstream(filename, std::ios::app);
and then ifstream>>CCity1;
class CPerson {
std::string m_strName;
std::string m_strEGN;
friend std::istream& operator>>(std::istream& is, CPerson& p) {
is >> p.m_strEGN >> p.m_strName;
return is;
}
};
class CCity {
std::string city;
std::vector<CPerson>people;
friend std::istream& operator>>(std::istream& is, CCity& p) {
is >> p.city;
CPerson temp("Empty", "Empty");
while (std::cin) {
is >> temp;
p.people.push_back(temp);
}
return is;
}