사용자 로그인을 설정해야하는 프로젝트를 진행 중입니다. 사용자 데이터는 클래스 구조의 파일에 저장됩니다. 이것은 로그인 기능입니다.
bool check_login(int n, string pass)
{
bool found = false;
account ac;
ifstream infile;
infile.open("final.dat",ios::binary);
if(!infile)
{
cout<<"File could not be open !! Press any Key...";
return false;
}
while(!infile.eof() && found==false)
{
infile.read(reinterpret_cast<char *> (&ac), sizeof(account));
if(ac.retacno()==n)
{
if(pass.compare(ac.retpassword())==0)
found=true;
return found;
}
}
infile.close();
return found;
}
class account
{
int acno;
string password;
string name;
string address;
char sex;
string phonenumber;
public:
void create_account(); //function to get data from user
void show_account() const; //function to show data on screen
void modify(); //function to add new data
void withdraw(int,int); //function to accept amount and subtract from balance amount
void donate(int,int); //function to accept amount and add to balance amount
void report() const; //function to show data in tabular format
int retacno() const; //function to return account number
string retpassword() const; //function to return password
};
이로 인해 런타임 오류가 발생합니다. 프로세스가 반환 값 255로 종료되었습니다. dev-c ++에서
여기에
infile.read(reinterpret_cast<char *> (&ac), sizeof(account));
수업에 적합하지 않습니다. 계정 인스턴스를 직렬화 및 역 직렬화하려면 코드를 추가해야합니다. 이제는 멤버의 생성자 (예 : 문자열)를 실행하지 않고 파일의 모든 항목을 계정 인스턴스로 읽어들입니다.
직렬화 / 역 직렬화하려면 예를 들어 >>
및 <<
연산자를 재정의 할 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다