Why is Every time I run this program it returns -1073741819 (0xC0000005)?

-3

Every time I run this it returns -1073741819 (0xC0000005) and doesn't show the name and id and I already inserted a name and id in the test.dat file.

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
using namespace std;
struct student
{
    string name;
    int id;
}
int main()
{
    student stud;
    fstream file1;
    file1.open("test.dat",ios::in|ios::binary);
    if(pol.fail()){
        cerr<<"an error occurred"<<endl;
        exit(1);
    }

    file1.seekg(0);
    while(file1.read((char*) &stud,sizeof(stud))){ 
        // *already written a txt in test.dat file*
        cout<<stud.name<<endl;
        cout<<stud.id<<endl;
    }
    file1.close();
}
c++
asked on Stack Overflow Sep 30, 2018 by Hęŋý Xǿxờ • edited Sep 30, 2018 by πάντα ῥεῖ

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0