c++ - 使用 c++ 连续检查文件中的任何更改?
问题描述
我必须检查使用 c++ 语言在文本文件中所做的任何更改。
解决方案
#include<stdio.h>
#include<iostream>
#include <fstream>
#include <string>
#include<stdlib.h>
#include <windows.h>
using namespace std;
string *fileContent = NULL;
int main()
{
//init app
do
{
ifstream inFile("C:\\Users\\ur185010\\Desktop\\uuid.txt");
string *content = new string((std::istreambuf_iterator<char>(inFile)),
(std::istreambuf_iterator<char>()));
//cout << content->c_str();
bool dataChanged = false;
{
if ((fileContent == NULL) || (strcmp(fileContent->c_str(), content->c_str()) != 0))
{
cout << "updated\n";
if (fileContent) {
delete fileContent;
}
fileContent = new string(content->c_str());
dataChanged = true;
}
}
if (dataChanged) {
printf("Data Changed \n", fileContent->c_str());
// call api to parse and update data base.
}
Sleep(5000);
} while (1);
getchar();
return 0;
//inFile.open("C:\\Users\\ur185010\\Desktop\\uuid.txt");
}
推荐阅读
- python - 在 Linux 上创建 python 虚拟环境
- javascript - 如何在 BootstrapVue 的 Carousel 组件中自定义控件和指示器?
- android - WebView 在 API 30 中不滚动
- locust - 在 Locust 中,使用 catch_response=True 验证响应时,我需要获取原始超时或连接错误
- mysql - 在列中搜索字符串
- java - 我如何解决这个问题 java.lang.NoClassDefFoundError: sun/security/ssl/HandshakeStateManager?
- php - Fetch 不返回任何内容
从第 1 页获取信息到 Query API 后 - python - 更改编码,从 SAP 下载文件
- java - 如何制作连续添加按钮
- javascript - 使用 Axios 请求 API - 未经授权