这代码,在2005下没问题,去2010下,就出现运行时错误,访问冲突。
[code=c]
#include<string>
using std::string;
class student
{
public:
    student();
    student(string,char,string, int );
    void setfn(string);
    void setmi(char);
    void setln(string);
    void setscore(int);
    string getfn();
    char getmi();
    string getln();
    int getscore();
private:
    string fn;
    char mi;
    string ln;
    int score;
};

[/code]
[code=c]
#include "strdent.h"

student::student()
{

}
student::student(string f,char m,string l,int s)
{
    setfn(f);
    setmi(m);
    setln(l);
    setscore(s);
}
student::~student()
{
    
}
void student::setfn(string f)
{
    this->fn = f;
}

void student::setmi(char m)
{
    this->mi = m;
}

void student::setln(string l)
{
    this->ln = l;
}

void student::setscore(int s)
{
    this->score = s;
}

string student::getfn()
{
    return fn;
}

char student::getmi()
{
    return mi;
}

string student::getln()
{
    return ln;
}

int student::getscore()
{
    return score;
}
[/code]
[code=c]
#include <iostream>
#include<fstream>
#include<string>
#include"strdent.h"
using namespace std;


void printstudent(student Student)
{
cout << Student.getln()<<" "<<Student.getmi()<<"  "<<Student.getln()<<"  "<<Student.getscore()<<endl;
}



int main()
{
    
    fstream binaryio;
    binaryio.open("d:\\student.dat",ios::out|ios::binary);
    student student1("TOMS",'T',"HAAH",85);
    student student2("Jack",'K',"HHHH",78);
    binaryio.write((char *)(&student1),sizeof(student));
    binaryio.write((char *)(&student2),sizeof(student));

    binaryio.close();
    binaryio.open("d:\\student.dat",ios::in|ios::binary);
    
    student stunew;
    binaryio.read((char*)(&stunew),sizeof(student));
    printstudent(stunew);
    binaryio.read((char *)(&stunew),sizeof(student));
    printstudent(stunew);
    
    binaryio.close();

}
[/code]