ROS Kinetic使用std::chrono::system_clock报错error: ‘std::chrono’ has not been declared

一个简单的获取系统时间的代码,头文件也对,在windows下跑了没问题。但在ROS中就报错,最后发现是C++标准的问题。

#include 
#include 
#include 
using namespace std;

int main()
{
    // 获取当前时间点
    std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
    // 将当前时间转换为 std::time_t 类型
    std::time_t time = std::chrono::system_clock::to_time_t(now);
       // 输出当前时间
    std::cout << "The current time is " << std::ctime(&time);
    
    return 0;
}

std::chrono::system_clock需要C++11标准,在功能包的CmakeList.txt中添加add_compile_options(-std=c++11)就可以了。
ROS Kinetic使用std::chrono::system_clock报错error: ‘std::chrono’ has not been declared_第1张图片

你可能感兴趣的:(C++,c++)