Przeciążenie operatora >>, wczytywanie z pliku do wektora

0

Mam sobie takie dwie klasy:

class Store
{
private:
	double surface_area_;	
	std::string name_;
	std::vector<Employee> employees_;
public:
	Store();	
	friend std::istream & operator >> (std::istream &is, Store &);
};
class Employee
{
private:
	std::string name_;
	double salary_;			
public:
	Employee();
};

I teraz chciałbym sobie przeciążyć operator >>, aby wczytać wszystkie dane z pliku .txt. Przykładowo, niech zawartość pliku będzie wyglądać tak (ilość elementów wektora nie jest z góry narzucona):

NazwaSklepu
111.11
NazwaPracownika1
2000
NazwaPracownika2
3000

Żeby wczytać pierwsze 2 zmienne to wiadomo, standard:

std::istream & operator >> (std::istream &is, Store &store)
{
	is >> store.name_ >> store.surface_area_;
	return is;
}

Natomiast jak tutaj zrobić wczytywanie do wektora?
W mainie wywołanie byłoby takie:

Store store;
std::ifstream fp;
fp.open("plik.txt");
fp >> store;
fp.close();
2

Dane w pliku:

aa
5
bb
6
cc
7
 #include <iostream>
#include <fstream>
#include <string>
#include <vector>

class Foo {
    int n;
    std::string str;
public:
    void clear_foo()
    {
        this->n = 0;
        this->str.clear();
    }

    friend std::ostream& operator<<(std::ostream& os, const Foo& foo)
    {
        os << foo.n << ' ' << foo.str;
        return os;
    }

    friend std::ifstream& operator >> (std::ifstream& in, Foo& foo)
    {
        std::getline(in, foo.str);
        std::string tmp;
        std::getline(in, tmp);
        foo.n = atoi(tmp.data());
        return in;
    }
};

class Kl {
    std::vector<Foo> v;    
    Foo tmp;
public:
    friend std::ostream& operator<<(std::ostream& os, const Kl& kl)
    {
        for (auto const& el : kl.v) {
            os << el << '\n';
        }
        return os;
    }

    friend std::ifstream& operator >> (std::ifstream& in, Kl& kl)
    {
        while (in >> kl.tmp) {
            kl.v.push_back(kl.tmp);
            kl.tmp.clear_foo();
        }
        return in;
    }
};
int main()
{
    Kl kl;
    std::ifstream fin("test.txt");
    if (fin) {
        fin >> kl;
    }
    std::cout << kl;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1