samedi 3 février 2018

Detect change in text file using C++ i without Infinite Loop?

I am reading a text file using C++. I am using the first line to indicate if the file has changed or not. For example, text file will look like :

  0
  9

After the text file has been changed I am flipping the first line. So, the new text file will look like:

  1
  5

C++ code will perform its functions after reading the new input from the text file. Currently, I am using infinite loop to detect changes in the text file. Is there any alternative implementation of detecting changes in the text file using C++? This is my solution so far:

   do{
      std::ifstream reader;
      reader.open(READFILE);
      if (!reader){
       printf("Error opening the reader file!!");
       exit(1);
     }
     reader >> status >> variable;

     if(status != reader_file_status){
       reader_file_status = status;
       return true
     }
  } while(true);

Aucun commentaire:

Enregistrer un commentaire