关于 检测文件是否被修改 如果修改就再次打印文件内容
int main(int argc, char* argv[])
{
fstream fs;
fs.open("a.txt", ios::in);
time_t t = 0;
while(1)
{
struct stat buf;
stat("a.txt", &buf);
cout << "tbuf =" << ctime(&buf.st_mtime) <<endl;
cout << "t =" << ctime(&t) << endl;
Sleep(1000);
if ( buf.st_mtime != t )
{
string str;
vector<string> id;
while(!fs.eof())
{
getline(fs,str); //按行读入
id.push_back(str);
cout << str <<endl;
}
t = buf.st_mtime;
}
Sleep(2000);
cout << "t =" << ctime(&t) << endl;
Sleep(5000);
}
fs.close();
/*system( "pause ");*/
printf("Hello World!\n");
getch();
return 0;
}
----------------------------
a.txt
111111
222222
333333
求问当我修改a.txt后 已经显示tbuf和t 不相等了 但是就是没法执行if语句 这是咋回事?