Is there a standard date/time class in C++?(C++ 中是否有标准的日期/时间类?)
问题描述
C++ stl 有标准时间类吗?或者我是否必须在写入流之前转换为 c 字符串.例如,我想将当前日期/时间输出到字符串流:
<前>time_t tm();ostringstream 南;南<strftime
首先格式化 tm,但如果 stl 具有可以从 time_t 值实例化的时间类,这似乎没有必要不是 STL 的一部分,但众所周知的库是 boost.
我会使用boost::date
.以下是一些示例:http://www.boost.org/doc/libs/1_55_0/doc/html/date_time/date_time_io.html#date_time.io_tutorial.
如果你还没有尝试过 boost,我鼓励你这样做,因为它可以让你免于许多讨厌的问题,因为它掩盖了大多数操作系统相关的事情,例如线程.boost
中的很多东西都是头文件(模板库).但是 datetime 需要一个 lib 或 dll.
Does C++ stl have a standard time class? Or do I have to convert to c-string before writing to a stream. Example, I want to output the current date/time to a string stream:
time_t tm(); ostringstream sout; sout << tm << ends;
In this case I get the current date/time written out as a number without any formatting. I can use
c- runtime function strftime
to format tm first, but that seems like it should not be necessary if the stl has a time class that can be instantiated from time_t value
Not part of STL but well known library is boost.
I would go the way of using boost::date
. Here are some examples: http://www.boost.org/doc/libs/1_55_0/doc/html/date_time/date_time_io.html#date_time.io_tutorial.
If you did not try out boost yet I encourage you to do so as it saves you from a lot of nasty issues, as it masks most OS dependent things like threading for example. Many things in boost
are header only (template libraries). However datetime requires a lib or dll.
这篇关于C++ 中是否有标准的日期/时间类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 中是否有标准的日期/时间类?


- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 静态初始化顺序失败 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01