我为strcpy收到此错误

时间:2014-12-10 08:34:53

标签: c++ fstream strcpy

我收到这些错误。在第一行和第二行,它表示没有匹配函数来调用' strcpy',我很确定我使用错误的预处理器指令,我使用#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));
}

1 个答案:

答案 0 :(得分:0)

要使用包含std::strcpy()的{​​{1}}(相当于C strcpy())功能是不够的,您必须包含fstream

cstring

另外(不知道#include <cstring> studentallinfo.FirstName的哪些类型)allinfo.LastName的参数必须可转换为std::strcpy()char*