• <small id='BDgcQ'></small><noframes id='BDgcQ'>

    <tfoot id='BDgcQ'></tfoot>
    • <bdo id='BDgcQ'></bdo><ul id='BDgcQ'></ul>

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

        C++中的时差

        时间:2023-06-30
        <tfoot id='OhZ0q'></tfoot>
      1. <small id='OhZ0q'></small><noframes id='OhZ0q'>

            <bdo id='OhZ0q'></bdo><ul id='OhZ0q'></ul>
            <legend id='OhZ0q'><style id='OhZ0q'><dir id='OhZ0q'><q id='OhZ0q'></q></dir></style></legend>

              <tbody id='OhZ0q'></tbody>

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

                  本文介绍了C++中的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有谁知道如何在 C++ 中以毫秒为单位计算时间差?我使用了 difftime 但它没有足够的精度我正在尝试测量什么.

                  Does anyone know how to calculate time difference in C++ in milliseconds? I used difftime but it doesn't have enough precision for what I'm trying to measure.

                  推荐答案

                  您必须使用一种更具体的时间结构,timeval(微秒分辨率)或 timespec(纳秒分辨率),但您可以手动进行相当容易:

                  You have to use one of the more specific time structures, either timeval (microsecond-resolution) or timespec (nanosecond-resolution), but you can do it manually fairly easily:

                  #include <time.h>
                  
                  int diff_ms(timeval t1, timeval t2)
                  {
                      return (((t1.tv_sec - t2.tv_sec) * 1000000) + 
                              (t1.tv_usec - t2.tv_usec))/1000;
                  }
                  

                  如果时间差异非常大(或者如果您有 16 位整数),这显然存在整数溢出问题,但这可能不是常见情况.

                  This obviously has some problems with integer overflow if the difference in times is really large (or if you have 16-bit ints), but that's probably not a common case.

                  这篇关于C++中的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C++ 将时间字符串从纪元转换为秒 下一篇:最快的时序解析系统

                  相关文章

                1. <legend id='l1nTx'><style id='l1nTx'><dir id='l1nTx'><q id='l1nTx'></q></dir></style></legend>
                  • <bdo id='l1nTx'></bdo><ul id='l1nTx'></ul>

                    1. <tfoot id='l1nTx'></tfoot>

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

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