C++11中挂起线程

C++11中用sleep_untill()函数挂起线程

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<thread>
#include<chrono>
#include<ctime>

int main()
{
    //获取系统当前的时间
    std::time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
    //将时间格式转换成本地时间类型
    std::tm* ptm = std::localtime(&tt);
    //输出当前的时间
    std::cout << "time is " << std::put_time(ptm,"%X") << std::endl;
    std::cout << "time is " << std::put_time(ptm,"%c") << std::endl;
    ptm->tm_min++;

    //挂起当前线程1分钟
    std::cout << "线程挂起1分钟,等待线程执行完毕..." << std::endl;
    std::this_thread::sleep_until(std::chrono::system_clock::from_time_t(mktime(ptm)));
    return 0;
}

你可能感兴趣的:(C++)