【发布时间】:2019-11-12 17:53:56
【问题描述】:
我需要使用某种形式的 Sleep() 来让用户跟上程序的速度并观察屏幕上的东西。我在使用任何使程序停止一小段时间的命令时遇到问题,但至少现在 Sleep() 似乎是我最好的选择。我已经包含 stdlib.h 并接受 _sleep() 并且当我运行程序时它说使用 Sleep() 因为它已被新库取代。并且在 stdlib.h Sleep() 中也确实存在。我遇到了一个完全的障碍,非常感谢任何建议! (与 2017 的错误不同,因为我使用的是 2019)
代码:
void startGame() {
//bool flag = true;
for (int a = 0; a < 10; a++) {
screenUpdate();
for (int i = 0; i < 4; i++) {
rowsShown[i]++;
}
Sleep(500); // this comes out with an error
//to show what the other one does
_sleep(500);
}
}
错误:
Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "Sleep" is undefined
Severity Code Description Project File Line Suppression State
Error C4996 '_sleep': This function or variable has been superceded by newer library or operating system functionality. Consider using Sleep instead. See online help for details.
【问题讨论】:
-
请将代码和错误以文字形式发布,注意图片。不是每个人都能看到图片。
-
怎么睡觉:stackoverflow.com/questions/4184468/sleep-for-milliseconds(注意接受的答案已经过时了,c++11还有一个)
-
我会改用这个:https://en.cppreference.com/w/cpp/thread/sleep_for 原因是它让你的代码更便携。
-
未来:从“输出”窗口复制错误信息。在 VS 中经常有一些有用的信息没有显示在错误窗口中。
-
嗯,一个好的开始是你确定你包含了正确的标题
Sleep()?
标签: c++ winapi visual-c++