c++ - 错误 : uint64_t was not declared in this scope when compiling C++ program

标签 c++ c++11 g++ c++-chrono

我正在尝试一个简单的程序来打印 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++ - 错误 : uint64_t was not declared in this scope when compiling C++ program,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32085291/

相关文章:

c++ - 从可调用参数创建的线程对象参数移动构建 C++11 线程

c++ - C++ 中分离线程的资源释放

c++ - GLM : Get position of plane-line-intersection

c++ - AVX __m256i 有符号 32 位元素的整数除法

C++ boost 理性类,floor 函数

c++ - 在 g++ 中是在后台使用 pthreads 的 C++ 11 线程模型吗?

c++ - 为什么一个简单的C++程序会产生这么多分支命令?在 Linux 上使用性能

c++ - 类对象没有正确修改其他类对象

c++ - 从 QMetaObject 检索 QMetaType

c++ - 在 Linux 中编译/链接多个 C++ 库