不幸的是,它不是直接回答你的问题,而是你问替代方法来实现需求,这可能会有帮助。
#include <windows.h>
#include <stdio.h>
#include <ctime>
using namespace std;
int main()
{
HANDLE _configfile;
FILETIME _configFileTimeCreate, _configFileTimeModified;
SYSTEMTIME _systemUTC;
time_t start_time = time(NULL);
for (;;)
{
time_t now = time(NULL);
time_t diff = now - start_time;
if ((diff % 10) == 0) {
_configfile = CreateFile(L"config.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(_configfile == INVALID_HANDLE_VALUE) {
printf("Could not open file, error %ul\n", GetLastError());
return -1;
}
if(!GetFileTime(_configfile, &_configFileTimeCreate, NULL, &_configFileTimeModified)) {
printf("Something wrong!\n");
return FALSE;
}
else {
FileTimeToSystemTime(&_configFileTimeModified, &_systemUTC);
printf("UTC System Time format:\n");
printf("Modified on: %02d/%02d/%d %02d:%02d\n", _systemUTC.wDay, _systemUTC.wMonth, _systemUTC.wYear,
_systemUTC.wHour, _systemUTC.wMinute);
}
CloseHandle(_configfile);
}
Sleep(1000);
}
return 0;
}
这不是太可怕和优化。请注意,它会改变你的程序行为,但是。以前可以编辑ini并立即启动它,但是对于静态的,他们必须重新启动程序。 – StoryTeller
@StoryTeller对我而言并不重要。那么你能否告诉我如何克服这种情况? –
您需要使用操作系统来获取并缓存上次文件修改的时间戳。它应该比阅读整个文件要快得多,所以你会看到性能提升,我想。 – StoryTeller