Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c+中,将输出屏幕冻结一定时间+; 我一直在尝试用C++制作一个蛇游戏。在使蛇移动的同时,我希望将蛇冻结到其位置1秒钟,然后打印新位置。 为此,我执行了以下功能: void wait_time(int wait_t){ time_t curr=time(NULL); time_t nav_t=time(NULL); while(1){ if (nav_t-curr==wait_t) { break; } else{ nav_t=time(NULL); } } }_C++ - Fatal编程技术网

在c+中,将输出屏幕冻结一定时间+; 我一直在尝试用C++制作一个蛇游戏。在使蛇移动的同时,我希望将蛇冻结到其位置1秒钟,然后打印新位置。 为此,我执行了以下功能: void wait_time(int wait_t){ time_t curr=time(NULL); time_t nav_t=time(NULL); while(1){ if (nav_t-curr==wait_t) { break; } else{ nav_t=time(NULL); } } }

在c+中,将输出屏幕冻结一定时间+; 我一直在尝试用C++制作一个蛇游戏。在使蛇移动的同时,我希望将蛇冻结到其位置1秒钟,然后打印新位置。 为此,我执行了以下功能: void wait_time(int wait_t){ time_t curr=time(NULL); time_t nav_t=time(NULL); while(1){ if (nav_t-curr==wait_t) { break; } else{ nav_t=time(NULL); } } },c++,C++,但是当这个函数被执行时,我以前的输出并没有保留下来。输出的一部分被删除。这是我控制所有功能的主要功能: void run_game(){ initial=time(NULL); inital_parameter(); gotoxy(0,2); game_display(); wait_time(1); game_movement();location_disp(); game_display(); gotoxy(0,100); }

但是当这个函数被执行时,我以前的输出并没有保留下来。输出的一部分被删除。这是我控制所有功能的主要功能:

void run_game(){
    initial=time(NULL);
    inital_parameter();
    gotoxy(0,2);
    game_display();
    wait_time(1);
    game_movement();location_disp();
    game_display();
    gotoxy(0,100);
}
使用C++11,您可以使用暂停执行一段时间

链接页面包括以下示例:

#include <iostream>
#include <chrono>
#include <thread>

int main()
{
    // using namespace std::chrono_literals; // C++14
    std::cout << "Hello waiter" << std::endl;
    auto start = std::chrono::high_resolution_clock::now();
    std::this_thread::sleep_for(std::chrono::seconds(2)); // C++11
    // std::this_thread::sleep_for(2s); // C++14
    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> elapsed = end-start;
    std::cout << "Waited " << elapsed.count() << " ms\n";
}
#包括
#包括
#包括
int main()
{
//使用命名空间std::chrono_literals;//C++14
std::cout使用C++11可以暂停执行一段时间

链接页面包括以下示例:

#include <iostream>
#include <chrono>
#include <thread>

int main()
{
    // using namespace std::chrono_literals; // C++14
    std::cout << "Hello waiter" << std::endl;
    auto start = std::chrono::high_resolution_clock::now();
    std::this_thread::sleep_for(std::chrono::seconds(2)); // C++11
    // std::this_thread::sleep_for(2s); // C++14
    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> elapsed = end-start;
    std::cout << "Waited " << elapsed.count() << " ms\n";
}
#包括
#包括
#包括
int main()
{
//使用命名空间std::chrono_literals;//C++14

std::cout使用您的标准库:

std::this_thread::sleep_for(2s);
2s
是一个时间文本,但您也可以执行以下操作

std::this_thread::sleep_for(std::chrono::seconds{2});

使用标准库:

std::this_thread::sleep_for(2s);
2s
是一个时间文本,但您也可以执行以下操作

std::this_thread::sleep_for(std::chrono::seconds{2});

第一条路
chrono
library和
std::this\u thread::sleep\u(您的时间)

第二种方式
unistd.h
具有2个功能
一个等待秒,另一个等待微秒

睡眠(1);



usleep(1000000);

第一条路
chrono
library和
std::this\u thread::sleep\u(您的时间)

第二种方式
unistd.h
具有2个功能
一个等待秒,另一个等待微秒

睡眠(1);



usleep(1000000);

注意计时文字是c++14,而不是c++11注意计时文字是c++14,而不是c++11作为旁注,请记住,执行睡眠将意味着如果用户按键(比如esc)您将继续睡眠,并忽略输入,直到您最终有时间阅读它作为旁注。请记住,执行睡眠将意味着如果用户按下一个键(如esc),您将继续睡眠,并忽略输入,直到您最终有时间阅读它