我从 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?
展示一个吃鱼的人:
关于c++ - boost 日期时间转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49473167/