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..

Recommended Answers

All 2 Replies

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

FLATMATE fl("John");
myvector.push_back(fl);

problem solved, thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.