Error: uint64_t was not declared in this area when compiling a C ++ program

I am trying to run a simple program to print a steady_clock timestamp value as shown below:

 #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; } 

But whenever I compile this g++ -o abc abc.cpp , I always get the error message:

 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 

Is there something wrong that I am doing?

+4
source share
2 answers

Obviously, I am not following certain recommendations, but simply trying to get you to work for you.

 #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; } 

and then compile using C ++ 11 (C ++ 0x in your case)

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

You must include the stdint.h file.

+3
source

All Articles