-2

I'm getting these errors. On the first line and second line, it says No matching function for call to 'strcpy', i'm pretty sure im using the wrong preprocessor directive, I'm using #include < fstream>

void writeStudents(vector<student> &studentVector){
ifstream studentinfo;
studenttowrite allinfo;
studentinfo.open("students.bin");
for (unsigned int x=0 ; x<studentVector.size(); x++) {
    allinfo.StuNo = studentVector[x].StuNo;
    strcpy(allinfo.FirstName, studentVector[x].FirstName);
    strcpy(allinfo.LastName, studentVector[x].LastName);
    allinfo.major = studentVector[x].major;
    allinfo.college = studentVector[x].college;
    allinfo.Age     = studentVector[x].Age;
    allinfo.Gpa     = studentVector[x].Gpa;
    studentinfo.write(reinterpret_cast<char *>
                    (&studentVector[x]), sizeof(student));
}
Huzaifa Imran
  • 11
  • 2
  • 2

1 Answers1

0

To use std::strcpy() (equivalent of C strcpy()) function including fstream is not enough, you must include cstring:

#include <cstring>

Also (not knowing what types are student and allinfo.FirstName, allinfo.LastName) arguments of std::strcpy() must be convertible to char* and const char*.

zoska
  • 1,684
  • 11
  • 23