使用时钟"storing"特定时间
"storing" a specific time with clock
所以我想知道我是否可以使用一个变量或其他东西,并保留clock
存储时的值。例如:
if (this)
that = Clock();
这样我就可以做了
if (that + 20000)//20 seconds later
dothing();
非常感谢任何帮助:D
你应该研究std::chrono
的东西,它有办法获得当前时间,添加持续时间,并做各种其他精彩的事情。
例如:
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main() {
auto start = system_clock::now();
while (duration_cast<seconds>(system_clock::now() - start).count() < 5)
;
// It is now 5 seconds later.
}
在c++11 中使用sleep_until
#include <iostream>
#include <chrono>
#include <thread>
int main()
{
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::chrono::seconds sec(2);
std::this_thread::sleep_until(now+sec);
std::cout << " done "<<std::endl;
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 从持续时间构造std::chrono::system_clock::time_point
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- while循环中while循环的时间复杂度是多少
- 使用简单类型列表实现的指数编译时间.为什么
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 在基于范围的for循环中使用结构化绑定声明
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- 在已经使用Git的情况下减少编译时间
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 从文本文件中读取时钟时间和事件时间并进行处理
- 具有未知值时的时间复杂性
- 使用时钟"storing"特定时间
- C++ Poco SQL 查询不返回具有'between'和'and'日期时间绑定的结果
- C++17:是编译器为(静态存储持续时间)const引用绑定创建的可修改的临时对象(和存储)
- 模板变量的绑定时间
- 如何判断约束绑定编码的时间限制