c++ - boost 日期时间转换错误

标签 c++ datetime boost

我从 synaptic 安装了 boost。

现在我需要将日期从/转换为字符串,但是当我编写如下代码时,

date dt{2018-9-14};

string str=to_simple_string(dt);

cout<<str<<endl;

它给出了一个错误:

/usr/include/boost/date_time/date_formatting.hpp:44: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
/usr/include/boost/date_time/date_formatting.hpp:49: undefined reference to `boost::gregorian::greg_month::as_long_string() const'

我该如何解决这个问题???

最佳答案

正如另一个答案所述,构造函数是错误的(使用逗号,或者您只需说 2018-9-14 等于 1995)。

接下来,你忘了链接 boost_date_time 库:

从全新的 16.04 机器开始:

apt update; apt install -yy build-essential libboost-all-dev
echo -e '#include <boost/date_time.hpp>\nint main(){std::cout<<boost::gregorian::to_simple_string({2018,9,14})<<std::endl;}' > test.cpp
g++ -std=c++11 test.cpp -lboost_date_time && ./a.out 

作品和版画

2018-Sep-14

授人以渔:What is an undefined reference/unresolved external symbol error and how do I fix it?

展示一个吃鱼的人:

enter image description here

关于c++ - boost 日期时间转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49473167/

相关文章:

c++ - 是否可以在运行时迭代 mpl::vector 而不实例化 vector 中的类型?

c++ - (不)在异常中使用 std::string

python - 如何在C++ Builder 2010(非Delphi)应用程序中嵌入Python?

ruby-on-rails - 如何按星期几 ruby​​ 获取日期

python - 如何从 Python 日期时间获取小时数?

MYSQL 查询/日期早于 1 周前(UTC 中的所有日期时间)

c++ - Boost 单元测试编译通过 Eclipse 失败

C++索引超出范围但没有在应该发生的时候发生

C++ 代码:: block 自动完成不工作

c++ - CMake Visual Studio 调试/发布 find_package