Timestamp of file in c++ -


i want check file see if been changed , if is, load again.. this, started following code getting me nowhere...

#include <sys/types.h> #include <sys/stat.h>  #include <unistd.h> #include <iostream>  using namespace std;  int main() {     struct stat st;     int ierr = stat ("readme.txt", &st);     if (ierr != 0) {             cout << "error";     }     int date = st.st_mtime;     while(1){             int newdate = st.st_mtime;             usleep(500000);             if (newdate==date){                     cout << "same file.. no change" << endl;             }             else if (newdate!=date){                     cout << "file changed" << endl;             }     } } 

all code print same file.. no change continuously.

that's because you're calling stat() outside loop.

the result stat() correct at particular moment. need call stat() again each time want check it.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -