I have the following code in C++:
typedef struct
{
int age;
int roomNumber;
} Student;
Student student;
student.age = 20;
student.roomNumber = 10;
vector<Student> studentV;
student.push_back(student);
student.push_back(student);
student.push_back(student);
Student student1[3];
int i;
for(vector<Student>::const_iterator iterator = studentV.begin();
iterator != studentV.end(); ++iterator,++i)
{
memcpy(&student1[i], iterator, sizeof(Student));
}
It show the following message for the memcpy part:
error: cannot convert 'std::vector<Student>::const_iterator {aka __gnu_cxx::__normal_iterator<const Student*, std::vector<Student> >}' to 'const void*' for argument '2' to 'void* memcpy(void*, const void*, size_t)'
What is the problem and how to fix it? is iterator can not be copied like this?