草庐IT

time_signed

全部标签

c++ - 如何使用 boost::date_time 读取 ISO 时区?

令我惊讶的是,boost::date_time似乎可以写入它无法读取的日期/时间字符串。考虑以下示例代码:#include#include#includeclassPointTime:publicboost::local_time::local_date_time{typedefboost::local_time::local_time_input_facetinput_facet_t;typedefboost::local_time::local_time_facetoutput_face_t;public:staticinput_facet_tconsts_input_facet;

c++继承私有(private)复制构造函数: how doesn't this yield a compile time error?

在C++中,如果我们有这个类classUncopyable{public:Uncopyable(){}~Uncopyable(){}private:Uncopyable(constUncopyable&);Uncopyable&operator=(constUncopyable&);};然后我们有一个派生类classDervied:privateUncopyable{};我的问题是:当编译器在派生类中生成默认的复制构造函数和赋值运算符时,为什么这不会生成编译时错误?生成的代码不会尝试访问基类私有(private)成员吗? 最佳答案

c++ - "All memory allocated on the stack is known at compile time"是什么意思?

阅读thisgreattutorial关于堆栈与堆,我对这句话有疑问:在堆栈上分配的所有内存在编译时都是已知的。我的意思是,如果我处于取决于用户输入的for循环中(i从0到X),并且在for我在堆栈上分配内存(例如创建一些类的新实例并放入类容器中),它不知道编译程序时堆栈将如何增长(它错过了用户的输入)。我是不是误会了什么? 最佳答案 对读者来说,所做的陈述稍微简化了一点。你是对的,堆栈本质上是动态的,实际分配的数量可能因动态输入而异。这是一个带有递归函数的简单示例:voidf(intn){intx=n*10;if(x==0)ret

【论文阅读笔记】TimesURL: Self-supervised Contrastive Learning for Universal Time Series

TimesURL:Self-supervisedContrastiveLearningforUniversalTimeSeriesRepresentationLearning摘要 学习适用于多种下游任务的通用时间序列表示,并指出这在实际应用中具有挑战性但也是有价值的。最近,研究人员尝试借鉴自监督对比学习(SSCL)在计算机视觉(CV)和自然语言处理(NLP)中的成功经验,以解决时间序列表示的问题。然而,由于时间序列具有特殊的时间特性,仅仅依赖于来自其他领域的经验指导可能对时间序列是无效的,并且难以适应多个下游任务。 在1和2中,研究发现不适当的正负样本构造可能引入不恰当的归纳偏差,既不能保持时

c++ - unsigned-signed 下溢机制

我知道以下内容unsignedshortb=-5u;由于下溢,评估为b为65531,但我不明白5u在转换为-5之前是否转换为带符号的int,然后重新转换回无符号以存储在b中,或者-5u是等于0-5u(不应该这样,-x是一元运算符) 最佳答案 5u是一个文字无符号整数,-5u是它的否定。无符号整数的否定定义为从2**n中减去,得到相同的结果包装从零减去的结果。 关于c++-unsigned-signed下溢机制,我们在StackOverflow上找到一个类似的问题:

c++ - 将 long int 转换为 const time_t

我有变量tmit:longtmit;。我在这段代码中出错:printf("Time:%s",ctime(&tmit));错误说:无法将参数“1”的“longint*”转换为“consttime_t*{akaconstlonglongint*}”到“char*ctime(consttime_t*)”我的问题是,如果我想查看日期,如何在不丢失任何有关时间的信息的情况下将long转换为time_t或如何更改此代码。我正在研究这个answer,但我得到了错误。 最佳答案 一般情况下,您不能这样做,因为std::time_t之间不需要有任何合

c++ - 从编译时已知的日历日期创建 `std::chrono::time_point`

This答案显示了如何将字符串解析为std::chrono::time_point,如下所示:std::tmtm={};std::stringstreamss("Jan9201412:35:34");ss>>std::get_time(&tm,"%b%d%Y%H:%M:%S");autotp=std::chrono::system_clock::from_time_t(std::mktime(&tm));如果我想从一个(公历)日历日期创建一个std::chrono::time_point,其年、月和日在编译时已知,是否有任何比上面建议的从字符串解析它更简单的方法?

C++::Boost::posix_time(经过的秒数。经过的小数秒)

我正在尝试对两个起初看起来并不难的问题给出答案。Q1:如何获取UTC.Now()和给定日期之间经过的秒数?A1:就像下面的代码一样!Q2:我如何确定自上次“完整”秒以来已经过去了多少小数秒?我想打印“total_elapsed_seconds.fractional_seconds”->“1234124.45”。我怎么做?A2:???#include#include#includeusingnamespacestd;usingnamespaceboost::gregorian;usingnamespaceboost::posix_time;voidmain(){ptimeJan1st19

c++ - 将 time_t 转换为 int

我想将给定时间转换为epoch(time_t),反之亦然。谁能告诉我这是什么例程或算法?谢谢更新epoch_strt.tm_sec=0;epoch_strt.tm_min=0;epoch_strt.tm_hour=0;epoch_strt.tm_mday=1;epoch_strt.tm_mon=1;epoch_strt.tm_year=70;epoch_strt.tm_isdst=-1;doublensecs=difftime(curtime,basetime);//currenttimefromsystem,Iconverrtingittostructtm但出于某种原因,这总是返回3

c++ - 警告 : Comparison between signed and unsigned integer expression

我在codepad.org上运行以下代码时出现此错误。“在成员函数‘doubleXchange::getprice(std::string)’中:第87行:警告:有符号和无符号整数表达式之间的比较”这是我的代码:#include#include#includeusingnamespacestd;classXchange{public:Xchange();//doesnothing(?)doublegetprice(stringsymbol);private:vectorstocks;};doubleXchange::getprice(stringsymbol){for(inti=0;i