0

Hi guys, I know what is meant by vector <string> myvector as it will just take every inputs as string when we are trying to store the inputs in myvector.

e.g. myvector.push_back(nick)

but what about if we declare the type of vector become like vector <FLATMATE> myvector?
Why it won't take any inputs and give some error?

e.g.

class FLATMATE
{
    string name;
    public: 
        FLATMATE() { name = "";}
        FLATMATE(string n){name = n;}
        string getName(){return name;}
        void setResident(string n){name = n;}
};

vector <FLATMATE> myvector

what is the valid input for myvector to store something? Just need to get this stuff around my head..

Edited by Bigbrain99: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Bigbrain99
0

First you have to declare an object of type FLATMATE and then push it onto the vector

FLATMATE fl("John");
myvector.push_back(fl);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.