-1

I'm trying to output the values of a vector array into a text but im getting this weird error

no opeartor "<<" matches the operands, operand types are : std::ofstream << Person

Here is my code

class Person {
public:
    Person(string, string, int);
    string get_name() {
        return name;
    }
    string get_family() {
        return family;
    }
    int get_age() {
        return age;
    }



private:
    string name;
    string family;
    int age;


};

    ofstream myfile;
    myfile.open("test.txt");

    vector <Person> persons;


    string N, F;
    int A;
    while (cin >> N >> F >> A) {

        Person tmpPerson(N, F, A);

        persons.push_back(tmpPerson);

        for (int i = 0; i < persons.size(); i++){
            myfile << persons[i] << " " << endl;
        }
        myfile.close();

    };

I have incuded the and tried everything, but this error, persist, would be very thankful for some help !

FreeSock
  • 51
  • 7

1 Answers1

0

You need to add a function helper like this for your custom class Person.

ostream& operator<<(ostream& os, const Person& p)  
{  
    os << p._N << ' '  << p._F << ' ' << p._A << std::end; 

    return os;  
}
Ratah
  • 279
  • 3
  • 11