c++ - boost 日期之前缺少模板参数

标签 c++ boost boost-date-time

在使用 boost 编译一个简单的日期解析测试时,我得到了一个缺少模板参数,这里是代码:

#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/date_time/gregorian/parsers.hpp"

boost::date_time::date test = boost::gregorian::from_us_string("07-Sep-2010");

编译器提示 错误:“test”之前缺少模板参数 boost::date_time::date test = boost::gregorian::from_us_string("07-Sep-2010");

我不明白我应该提供什么模板参数,或者为什么我应该首先提供模板参数。根据我的口味,这似乎有点太多样板代码:)

最佳答案

应该是boost::gregorian::date而不是 boost::date_time::date。 除此之外,你可以使用

auto test = boost::gregorian::from_us_string("07-Sep-2010");

如果您使用的是 C++11。

关于c++ - boost 日期之前缺少模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31051373/

相关文章:

c++ - 用DLL注入(inject)C++读写

c++ - 定位因整数除法导致的数值错误

c++ - 负数组索引和看似冗余的模板使用

boost - 使用 clang-tidy 处理大量与 boost 单元测试相关的警告

C++:我应该使用 Boost.Date_Time Posix 时间还是本地时间?

c++ - 为什么 "identifier"被认为与 "identifier()"有歧义,当它们被不同地使用时?

c++ - Q_DECLARE_METATYPE 一个 boost::multi_array

c++ - 无法将 »boost::gregorian::date_duration« 转换为 »int

c++ - 如何获取两个 boost ptime 之间的每个单独日期

c++ - basic_string.h 中的_GLIBCXX_FULLY_DYNAMIC_STRING