• <i id='2pM2J'><tr id='2pM2J'><dt id='2pM2J'><q id='2pM2J'><span id='2pM2J'><b id='2pM2J'><form id='2pM2J'><ins id='2pM2J'></ins><ul id='2pM2J'></ul><sub id='2pM2J'></sub></form><legend id='2pM2J'></legend><bdo id='2pM2J'><pre id='2pM2J'><center id='2pM2J'></center></pre></bdo></b><th id='2pM2J'></th></span></q></dt></tr></i><div id='2pM2J'><tfoot id='2pM2J'></tfoot><dl id='2pM2J'><fieldset id='2pM2J'></fieldset></dl></div>

      <small id='2pM2J'></small><noframes id='2pM2J'>

          <bdo id='2pM2J'></bdo><ul id='2pM2J'></ul>
        <tfoot id='2pM2J'></tfoot>
        <legend id='2pM2J'><style id='2pM2J'><dir id='2pM2J'><q id='2pM2J'></q></dir></style></legend>

      1. C++ 中是否有标准的日期/时间类?

        时间:2024-05-11
      2. <legend id='YFYkZ'><style id='YFYkZ'><dir id='YFYkZ'><q id='YFYkZ'></q></dir></style></legend>

              <bdo id='YFYkZ'></bdo><ul id='YFYkZ'></ul>

              <small id='YFYkZ'></small><noframes id='YFYkZ'>

              <tfoot id='YFYkZ'></tfoot>

              <i id='YFYkZ'><tr id='YFYkZ'><dt id='YFYkZ'><q id='YFYkZ'><span id='YFYkZ'><b id='YFYkZ'><form id='YFYkZ'><ins id='YFYkZ'></ins><ul id='YFYkZ'></ul><sub id='YFYkZ'></sub></form><legend id='YFYkZ'></legend><bdo id='YFYkZ'><pre id='YFYkZ'><center id='YFYkZ'></center></pre></bdo></b><th id='YFYkZ'></th></span></q></dt></tr></i><div id='YFYkZ'><tfoot id='YFYkZ'></tfoot><dl id='YFYkZ'><fieldset id='YFYkZ'></fieldset></dl></div>

                    <tbody id='YFYkZ'></tbody>
                  本文介绍了C++ 中是否有标准的日期/时间类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  C++ stl 有标准时间类吗?或者我是否必须在写入流之前转换为 c 字符串.例如,我想将当前日期/时间输出到字符串流:

                  <前>time_t tm();ostringstream 南;南<

                  在这种情况下,我将当前日期/时间写成一个没有任何格式的数字.我可以用c- 运行时函数 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++ 中是否有标准的日期/时间类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在输出之前按值对 std::map 进行排序 &amp;破坏 下一篇:引用类型的 std::optional 特化

                  相关文章

                • <tfoot id='P6EBf'></tfoot>
                  <legend id='P6EBf'><style id='P6EBf'><dir id='P6EBf'><q id='P6EBf'></q></dir></style></legend>

                    • <bdo id='P6EBf'></bdo><ul id='P6EBf'></ul>

                    <small id='P6EBf'></small><noframes id='P6EBf'>

                      <i id='P6EBf'><tr id='P6EBf'><dt id='P6EBf'><q id='P6EBf'><span id='P6EBf'><b id='P6EBf'><form id='P6EBf'><ins id='P6EBf'></ins><ul id='P6EBf'></ul><sub id='P6EBf'></sub></form><legend id='P6EBf'></legend><bdo id='P6EBf'><pre id='P6EBf'><center id='P6EBf'></center></pre></bdo></b><th id='P6EBf'></th></span></q></dt></tr></i><div id='P6EBf'><tfoot id='P6EBf'></tfoot><dl id='P6EBf'><fieldset id='P6EBf'></fieldset></dl></div>