提高日期时间转换错误

2024-01-09

我安装了来自 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

教人如何钓鱼:什么是未定义的引用/未解析的外部符号错误以及如何修复它? https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix

展示一个人吃鱼:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

提高日期时间转换错误 的相关文章

随机推荐