This is the code snippet, wherein "s" is a array of class objects.
for(int i =0; i<4; i++)
{
cout<<"Student "<<i+1<<": "<<endl;
cout<<"Enter regno: ";
cin>>regno;
cout<<"Enter name: ";
cin>>name;
cout<<"Enter cgpa: ";
cin>>cgpa;
s[i].setregno(regno);
s[i].setname(name);
s[i].setcgpa(cgpa);
size[i] = s[i].getname().size();
fout.write( (const char*) s[i].getregno(), sizeof(int));
fout.write((const char* ) s[i].getcgpa(), sizeof(float));
fout.write(reinterpret_cast<char *>(&size[i]), sizeof(int));
fout.write(s[i].getname().c_str(), size[i]);
}
I am getting the following error message while compiling: invalid cast from type 'float' to type 'const char*'
If I include & after the typecasting inside of write, I get this error: lvalue required as unary '&' operand