title: How to read a text file in c++?
body: <p>I want to detect a predefined specific content in a video. For this I use an already identified piece of video separately and another input video. I have read the data in the identified video and bite array was saved in a text file. Now I want to compare the content of saved text file with the input video content.</p>
  
  <p>This is my code</p>
  
  <pre><code>    void CFfmpegmethods::VideoRead(){
      av_register_all();
      avformat_network_init();
      ifstream inFile;
      inFile.open("H:\\Sanduni_projects\\sample_ad.txt");
      const char *url = "H:\\Sanduni_projects\\ad_1.mp4";
      AVDictionary *options = NULL;
      AVFormatContext *s = avformat_alloc_context();
  
      AVPacket *pkt = new AVPacket(); //this structure stores compressed data
  
      //open an input stream and read the header
      int ret = avformat_open_input(&amp;s, url, NULL,NULL);
  
      //avformat_find_stream_info(s, &amp;options); //finding the missing information 
  
      if (ret &lt; 0)
          abort();
  
      if (!inFile) {
          cerr &lt;&lt; "Unable to open file datafile.txt";
          exit(1);   // call system to stop
      }
  
      av_dict_set(&amp;options, "video_size", "640x480", 0);
      av_dict_set(&amp;options, "pixel_format", "rgb24", 0);
  
      if (avformat_open_input(&amp;s, url, NULL, &amp;options) &lt; 0){
          abort();
      }
      av_dict_free(&amp;options);
      AVDictionaryEntry *e;
  
      if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
          fprintf(stderr, "Option %s not recognized by the demuxer.\n", e-&gt;key);
          abort();
      }
  
      int i = 1;
      int64_t duration = 0;
      int size = 0;
      uint8_t *data; //Unsigned integer type with a width of exactly 8 bits.
      int sum = 0;
  
      int total_size = 0;
      int64_t total_duration = 0;
      int packet_size = 0;
      int64_t stream_index = 0;
      int64_t bit_rate = 0;
      AVBufferRef *buf;
  
      //writing data to a file
      outdata.open("H:\\Sanduni_projects\\sample_ad.txt");
      //outdata.open("H:\\Sanduni_projects\\log.txt");
  
      if (!outdata){
          cerr &lt;&lt; "Error: file could not be opened" &lt;&lt; endl;
          exit(1);
      }
  
      //Split what is stored in the file into frames and return one for each call
      //returns the next frame of the stream
  
      while(1){
          int frame = av_read_frame(s, pkt); //one frame is readed.
          if (frame &lt; 0) break;
          size = pkt-&gt;size;
          data = pkt-&gt;data;
  
          for (int j = 0; j &lt; size; j++){
              for (int k = 0; k &lt; 12; k++){
                  while (!inFile.eof){
  
  
                  }
                  //if (data[j] != ) break;
              }
          }
  
          //int decode = avcodec_send_packet(avctx, pkt);
      }
  
      //make the packet free
      av_packet_unref(pkt);
      delete pkt;
  
      cout &lt;&lt; "total size: " &lt;&lt; total_size &lt;&lt; endl;
      cout &lt;&lt; "total duration:" &lt;&lt; total_duration &lt;&lt; endl;
  
      outdata.close();
  
      //Close the file after reading
      avformat_close_input(&amp;s);
  }
  
  
  void CFfmpegmethods::SampleAdCreation(){
      av_register_all();
      const char *url_ref = "H:\\Sanduni_projects\\sample_ad.mp4";
      AVDictionary *options = NULL;
      AVDictionary *options_ref = NULL;
      AVFormatContext *s = avformat_alloc_context();
      AVPacket *pkt = new AVPacket(); //this structure stores compressed data
  
  
      //open an input stream and read the header
      int ret = avformat_open_input(&amp;s, url_ref, NULL, NULL);
  
      if (ret &lt; 0)
          abort();
  
      av_dict_set(&amp;options, "video_size", "640x480", 0);
      av_dict_set(&amp;options, "pixel_format", "rgb24", 0);
  
      if (avformat_open_input(&amp;s, url_ref, NULL, &amp;options) &lt; 0){
          abort();
      }
  
      av_dict_free(&amp;options);
      AVDictionaryEntry *e;
  
      if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
          fprintf(stderr, "Option %s not recognized by the demuxer.\n", e-&gt;key);
          abort();
      }
  
      uint8_t *data; 
  
      //writing data to a file
      outdata.open("H:\\Sanduni_projects\\sample_ad.txt");
  
      if (!outdata){
          cerr &lt;&lt; "Error: file could not be opened" &lt;&lt; endl;
          exit(1);
      }
  
      for (int m = 0; m &lt; 12; m++){
          int size = pkt-&gt;size;
          int frame = av_read_frame(s, pkt); 
          if (frame &lt; 0) break;
  
          data = pkt-&gt;data;
  
          for (int j = 0; j &lt; size; j++){
              outdata &lt;&lt; data[j];
          } outdata&lt;&lt;endl;
      }
  
      //make the packet free
      av_packet_unref(pkt);
      delete pkt;
  
      outdata.close();
  
      //Close the file after reading
      avformat_close_input(&amp;s);
  }
  </code></pre>