Hi,

I have to acess a vector, which is a member of a structure...

Could you please help me..

Recommended Answers

All 3 Replies

Well its really simple

struct student
{
std::string name;
double midterm, final;
std::vector<double> assignments;
};

int main()
{
struct student a_student;
a_student.assignments.push_back(value);
return 0;
}

Hi gerard,

Thanks for the info.. But , i need to retrieve the information that has pushed. Could you please help me..

Ok, if you want to retrieve the info at the last use "back"

a_student.assignments.back()

If you want to retrieve from anywhere else using an index, use "at"

a_student.assignments.at(4)

See this link for more info

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.