草庐IT

create_clock

全部标签

c++ - C++向chrono::system_clock::time_point添加月份

如何将chrono::system_clock::time_point值加数月?谢谢! 最佳答案 概述这是一个非常有趣的问题,有几个答案。“正确”的答案是您必须针对特定应用程序决定的。使用月份,您可以选择按时间顺序进行计算或进行日历计算。按时间顺序的计算处理时间点和持续时间的常规单位,例如小时,分钟和秒。日历计算处理不规则的日历,该日历主要用来给日子起令人难忘的名字。年表计算如果问题是关于future几个月的物理过程,那么物理学并不关心不同的月份有不同的长度,因此按时间顺序计算就足够了:婴儿要在9个月内到期。从现在开始的6个月后,这

c++ - 如何将 std::chrono::high_resolution_clock::now() 转换为毫秒、微秒...?

我从Howtogetduration,asintmilli'sandfloatsecondsfrom?得到了这段代码#include#includeintmain(intargc,char*argv[]){autot0=std::chrono::high_resolution_clock::now();autot1=std::chrono::high_resolution_clock::now();std::chrono::durationfs=t1-t0;std::chrono::millisecondsd=std::chrono::duration_cast(fs);std::co

c++ - 为什么我需要从主线程使用 `pthread_exit()`,而它不是由 `pthread_create` 创建的?

我对一些正在测试以开始理解posix线程的代码有疑问。我有这个基本代码:#include#include#include#includeusingnamespacestd;void*printInfo(void*thid){longtid;tid=(long)thid;printf("Hellofromthread%ld.\n",tid);pthread_exit(NULL);}intmain(intargc,charconst*argv[]){intnum=8;pthread_tthreadlist[num];intrc;longt;for(t=0;t非常简单的代码,启动线程并从中打

c++ - 语法糖 : automatically creating simple function objects

我要实现一组类模板和两个特殊变量,_1和_2.他们应该使以下内容成为合法代码://Sortascendingstd::sort(a,a+5,_1>_2);//Outputtoastreamstd::for_each(a,a+5,std::cout(std::cout,""),_1+5);我想_1*5也应该产生一个一元函数,以及_1/5等。不允许提升不允许使用lambda现在我有非常对模板和模板元编程的经验很少,所以我什至不知道从哪里开始以及我的类模板的结构应该是什么样子。我特别困惑,因为我不知道在我的类模板中是否必须为所有这些编写实现operator=,operator>>,opera

C++/QML : How to define and handle multiple contexts for dynamically created components?

基本上我的情况是这样的:我有一个扩展QQuickView的类,它通过设置上下文属性将某些对象从C++公开到QML。显示的View是从QML创建的,并且都是同一定制组件的不同实例;当某些事件发生时会创建新View,当这种情况发生时,现有View应显示最初在C++端分配给它们的对象,而新View应显示分配给它们的对象。所以,在C++方面,我有这样的东西:WindowManager::WindowManager(QQuickView*parent):QQuickView(parent){//Settingthesourcefiletousethis->setSource(QUrl("qrc:

c++ - 在 ubuntu 中找不到 pthread_create

我正在尝试在Ubuntu上运行cocos2d-x。它显示此错误:--LookingforIceConnectionNumberinICE--LookingforIceConnectionNumberinICE-found--FoundX11:/usr/lib/x86_64-linux-gnu/libX11.so--FoundOpenGL:/usr/lib/x86_64-linux-gnu/libGL.so--Lookingforincludefilepthread.h--Lookingforincludefilepthread.h-found--Lookingforpthread_cr

c++ - std::chrono::steady_clock::now 如何报告错误?

这与mypreviousquestion有关我问std::chrono::steady_clock::now是否应该是noexcept。现在我知道了,我应该想知道这个函数是如何报告错误的吗?例如,此功能在Linux上的常见实现使用clock_gettime可以返回错误。 最佳答案 Linuxclock_gettime工具可能报告的所有错误在std::chrono::steady_clock::now()的调试实现中是不可能的.错误是:intclock_gettime(clockid_tclk_id,structtimespec*tp

C++ WIN API : When creating a child process using CreateProcess, 是否需要使输入参数具有全局生命周期?

我对C++和WindowsAPI都很陌生。今天突然想到是不是需要把CreateProcess的入参保持一个长生命周期。根据MSDN:BOOLWINAPICreateProcess(_In_opt_LPCTSTRlpApplicationName,_Inout_opt_LPTSTRlpCommandLine,_In_opt_LPSECURITY_ATTRIBUTESlpProcessAttributes,_In_opt_LPSECURITY_ATTRIBUTESlpThreadAttributes,_In_BOOLbInheritHandles,_In_DWORDdwCreationFl

c++ - CLOCKS_PER_SEC 与 std::clock() 的结果不匹配

我正在使用以下短程序来测试std::clock():#include#includeintmain(){std::clock_tBegin=std::clock();intDummy;std::cin>>Dummy;std::clock_tEnd=std::clock();std::cout但是,在等待几秒钟输入“虚拟”值后,我得到以下输出:CLOCKS_PER_SEC:1000000Begin:13504End:13604Difference:100这显然没有多大意义。无论我等多久,差异总是在100左右。我错过了什么?有没有我忘记包含的标题?我正在使用带有GCC4.2的Xcode。

c++ - 没有对 'pthread_create' 的匹配函数调用

我正在使用Xcode和C++制作一个简单的游戏。问题出在以下代码:#includevoid*draw(void*pt){//...}void*input(void*pt){//....}voidGame::create_threads(void){pthread_tdraw_t,input_t;pthread_create(&draw_t,NULL,&Game::draw,NULL);//Errorpthread_create(&input_t,NULL,&Game::draw,NULL);//Error//...}但是Xcode给我错误:“没有匹配的函数调用‘pthread_crea