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++ 中是否有标准的日期/时间类?
基础教程推荐
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
