Question about Vectors

I have a vector of structs:

std::vector <teststruct> vec;

I am reading in the struct from a file -


teststruct *var11 = (teststruct*)malloc(sizeof(teststruct));

fread(var11, sizeof(char), sizeof(teststruct), file1);

I am trying to store this struct into an array using push_back but I receive an error message stating that push_back does not exist.  

    vec.push_back(var11);
jeweeAsked:
Who is Participating?
 
chip3dConnect With a Mentor Commented:
hi jewee, try

vec.push_back(*var11);

push_back of std::vector <teststruct> expect a type of teststruct and not teststruct*
0
 
jeweeAuthor Commented:
Funny, i thought I tried that.  It works.  Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.