Проверять наличие каких-либо изменений в файле с помощью c ++? - PullRequest
0 голосов
/ 21 февраля 2019

Я должен проверить наличие изменений в текстовом файле на языке c ++.

1 Ответ

0 голосов
/ 21 февраля 2019
#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");

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...