struct student
{
int identity;
char name[MAX];
int no_assessment;
char assessmenttask[MAX];
int mark;
};
void appendbfile(char filename [MAX])
{
ofstream writeb;
char filenameb [MAX];
strcpy(filenameb,filename);
student s;
strcat(filenameb,".dat");
cout<<"--------------------------------"
<<endl
<<"Begin appending for binary file "
<<filenameb
<<endl
<<endl;
cout<<"Enter student id: ";
cin>>s.identity;
cout<<"Enter student name: ";
cin>>s.name;
writeb.open(strcpy(filenameb,".dat"),ios::binary);
writeb.seekp(0,ios::end);
writeb.write (reinterpret_cast <const char *>(&s), sizeof (s));
writeb.close();
}
프로그램을 실행할 수는 있지만 레코드가 이진 파일에 추가되는 것 같습니다. 누군가 나를 봐줄 수 있습니까?캔트가 이진 파일에 레코드를 추가합니다.
감사
열기 함수에ios::app
플래그를 전달해야
왜이 코드 조각이 작동하지 않는지 알 수 없습니다. 아마 다른 문제가 생겼을거야. –
왜 오픈 콜에 strcpy가 있습니까? – perreal
학생 정의를 게시 할 수 있습니까? – billz