【问题标题】:Get current ISO datetime string using boost使用 boost 获取当前 ISO 日期时间字符串
【发布时间】:2014-05-09 17:42:09
【问题描述】:

只是想像这样将时间戳记录到输出文件中:

//#include <boost/date_time.hpp>

boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
std::cout << boost::posix_time::to_iso_extended_string(now) << std::endl;

// ideally one line
std::cout << boost::posix_time::to_iso_extended_string(
            boost::posix_time::second_clock::local_time()) << std::endl;

在 boost 中出现错误:

boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_extended_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::ostream&)': /usr/include/boost/date_time/date_formatting.hpp:44: undefined reference toboost::gregorian::greg_month::as_short_string() const' /usr/include/boost/date_time/date_formatting.hpp:49:未定义对`boost::gregorian::greg_month::as_long_string() const'的引用

我知道这可能是我最终没有提升但不确定如何调试的问题,有什么想法吗?

【问题讨论】:

  • 你使用哪个版本的 boost?

标签: date datetime boost time iso


【解决方案1】:

您需要链接适当的库。根据您的构建系统,这可能意味着将 -lboost_date_time 之类的内容添加到您的链接或最终构建命令中。

每当您看到“未定义的引用”时,这意味着您的代码编译得很好,但是您的构建中缺少一个库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2020-04-07
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    相关资源
    最近更新 更多