-3

I have to check for any changes made in a text file using c++ language.

  • Possible duplicate of [How to retrieve files digital signature information?](https://stackoverflow.com/questions/15024583/how-to-retrieve-files-digital-signature-information) – styphNate Feb 21 '19 at 09:34
  • https://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c – com Feb 21 '19 at 09:37

1 Answers1

-2
#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");

}
  • Check if the file signature changed instead of checking if the content has changed. – styphNate Feb 21 '19 at 09:33
  • Even when answering your own questions you should at least attempt to [write a good answer](https://stackoverflow.com/help/how-to-answer). Code-only answers encourages [cargo-cult programming](https://en.wikipedia.org/wiki/Cargo_cult_programming) which is bad and highly discouraged. – Some programmer dude Feb 21 '19 at 09:36