我一直在创建一个空闲程序,以在鼠标和键盘处于非活动状态时以分钟为单位进行计数。这是我到目前为止所拥有的:
using namespace std;
while(true)
{
GetLastInputInfo(&last_info);
tickCount = GetTickCount();
int minutes = (tickCount - last_info.dwTime) / 60000;
count++;
if((minutes >= 1) && (count%3000==0))
{
ifstream in("in.txt");
ofstream out("out.txt");
float sum;
in >> sum;
sum = sum++;
out << sum;
out << in.rdbuf();
out.close();
in.close();
}
std::cout << "Idle Time: " << minutes << " minutes." << std::endl;
}
}
当我让它空闲一分钟时,“sum”说它是 1,然后我关闭程序并再次打开它一分钟,“sum”说它是 2。我关闭程序并再打开一分钟,然后它恢复到 1。为什么会这样?