Tag: chrono

获得时间以来,以毫秒为单位,最好使用C ++ 11 chrono

我想要的只是从毫秒到纪元的时间,并把它存储在一个无符号的长整数。 我发现这个相关的问题 。 但说实话,这不是执行如此简单任务的最简单的方法,是吗? 我希望有更简单的东西,但在std :: chrono引用中找不到任何东西。 任何build议是最受欢迎的。 我不一定要使用std::chrono ,但我希望它是平台独立的。

精确的时间测量

我在C ++中使用time.h来测量函数的时间。 clock_t t = clock(); someFunction(); printf("\nTime taken: %.4fs\n", (float)(clock() – t)/CLOCKS_PER_SEC); 不过,我总是把时间拿到0.0000。 时钟()和t分别打印时,具有相同的值。 我想知道是否有方法在C ++中精确地测量时间(可能是以纳秒为单位)。 我正在使用VS2010。

在GCC的std :: put_time实现状态?

我试图编译这个使用GCC的示例程序 (testing版本4.5.1,4.6.3,4.8.4): #include <iostream> #include <iomanip> #include <ctime> #include <chrono> using std::chrono::system_clock; int main() { system_clock::time_point now = system_clock::now(); std::time_t now_c = system_clock::to_time_t( now – std::chrono::hours(24)); std::cout << "One day ago, the time was " << std::put_time(std::localtime(&now_c), "%F %T") << '\n'; } 但它告诉我: prog.cpp: In function 'int main()': prog.cpp:14:18: error: 'put_time' is not a member […]