0

before writing some data in the file I want to check that this file is empty or not. If it is empty then I have to write a matrix with 0 value in it. so, tell me please how can I do it?

 void details(int arr[][10])  // assumed that this matrix already contains 0 
                               //values 
{



int m1 = 10;
int n1 = 10;

ofstream fout;
fout.open("bookingb1.text" , ios::out); 
                                                  // here i wanted to check.

unordered_map<string , long long>m;


    cout<<"enter your name :"<<endl;
    cin.ignore();
    getline(cin,name);
    cout<<"register your aadhar id:"<<endl;
    cin>>id;
    m.insert({name , id});

    for(auto i = m.begin(); i!=m.end(); i++)
        fout<<i->first<<"        "<<i->second<<endl;
        fout.close();


       book(arr);






}
bruno
  • 7
  • 5

1 Answers1

0

The Function tellg() returns the read (get) position of the file and we opened the file with the read (get) position at the end using std::ios::ate . So if tellg() returns 0 it must be empty.