简体   繁体   English

在控制台上显示C ++中.txt文件的动态更改

[英]Show on Console the dynamic changes of a .txt file in C++

Here is my requirement: " I need to show to the user on a Console window, the output of a .txt file which will be modified continuously by a Third party application " 这是我的要求:“ 我需要在控制台窗口上向用户显示.txt文件的输出,该文件将被第三方应用程序连续修改

I have this code from cplusplus.com : 我有cplusplus.com的这段代码:

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;
  ifstream myfile ("test_results.txt");
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}

Do I need any sort of time counter to read that file at certain regular intervals of time? 我是否需要某种类型的计时器,以一定的固定时间间隔读取该文件? Guide me, thanks in advance... 指导我,在此先感谢...

There are two approaches. 有两种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM