错误:编译C程序时未在此作用域中声明uint64_t

我正在尝试一个简单的程序来打印steady_clock的时间戳值,如下所示:
#include <iostream>
#include <chrono>
using namespace std;
int main ()
{
  cout << "Hello World! ";
  uint64_t Now = duration_cast<milliseconds>(steady_clock::Now().time_since_epoch()).count();
  cout<<"Value: " << Now << endl;

  return 0;
}

但每当我像这样g -o abc abc.cpp一样编译时,我总是收到一个错误

In file included from /usr/include/c++/4.6/chrono:35:0,from abc.cpp:2:
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard,C++0x. This support is currently experimental,and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
abc.cpp: In function âint main()â:
abc.cpp:7:3: error: âuint64_tâ was not declared in this scope
abc.cpp:7:12: error: expected â;â before âNowâ
abc.cpp:8:22: error: âNowâ was not declared in this scope

我在做什么事吗?

解决方法

显然,我并没有遵循某些最佳实践,只是试图让事情适合你
#include <iostream>
#include <chrono>
#include <cstdint> // include this header for uint64_t

using namespace std;
int main ()
{
  {
    using namespace std::chrono; // make symbols under std::chrono visible inside this code block
    cout << "Hello World! ";
    uint64_t Now = duration_cast<milliseconds>(steady_clock::Now().time_since_epoch()).count();
    cout<<"Value: " << Now << endl;
  }

  return 0;
}

然后使用C 11启用编译(在您的情况下为c 0x)

g++ -std=c++0x -o abc abc.cpp

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...