boost::core模块实现修改std的日期顺序

445 篇文章 ¥29.90 ¥99.00
本文介绍了如何使用Boost库的boost::core::swap_date_order函数来修改std::chrono日期的顺序,以适应不同地区日期格式的需求。通过示例代码展示了如何交换日期顺序,并强调该函数不会改变原始日期对象,而是返回新的日期对象。同时提到Boost库还提供了其他日期时间处理工具,增强了程序的可读性和可维护性。

boost::core模块实现修改std的日期顺序

在编程中,很多情况下需要处理日期时间相关的数据。在不同的国家和地区,人们使用的日期格式不尽相同,例如在美国日期一般是以月/日/年的顺序表示,而在中国则是以年/月/日的顺序表示。因此,在不同的场景下,我们需要修改程序所使用的日期顺序。

在C++标准库中,std::chrono::year_month_day和std::chrono::local_days等类提供了日期时间处理的支持。然而,它们默认的日期顺序并不一定适用于所有场景。

为了解决这个问题,Boost库提供了一个核心模块boost::core::swap_date_order,可以用来交换日期顺序。

以下是一个示例代码,演示了如何使用boost::core::swap_date_order模块来交换日期顺序:

#include <iostream>
#include <boost/core/swap.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>

int main()
{
    // 定义日期
    boost::gregorian::date d(2023, 6, 16);

    // 输出日期
    std::cout << "before swap: " << d << std::endl;

    // 交换日期顺序
    boost::core::swap_date_order(d);

    // 输出日期
    std::cout << "after swap: " << d
usr/bin/ld: CMakeFiles/rgbd_tum.dir/Examples/RGB-D/rgbd_tum.cc.o: in function `main': rgbd_tum.cc:(.text.startup+0x559): undefined reference to `cv::imread(std::string const&, int)' /usr/bin/ld: rgbd_tum.cc:(.text.startup+0x75f): undefined reference to `cv::imread(std::string const&, int)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::getTextSize(std::string const&, int, double, int, int*)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::FileStorage::FileStorage(std::string const&, int, std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::namedWindow(std::string const&, int)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::FileNode::string() const' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::FileStorage::operator[](std::string const&) const' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::error(int, std::string const&, char const*, char const*, int)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `DBoW2::FORB::toString(cv::Mat const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `pangolin::CreateWindowAndBind(std::string, int, int, pangolin::Params const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::write(cv::FileStorage&, std::string const&, int)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::write(cv::FileStorage&, std::string const&, double)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::load(std::string&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `pangolin::Split(std::string const&, char)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> const> const&, std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::char_traits<char> >::save(std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `pcl::visualization::CloudViewer::CloudViewer(std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `DBoW2::FORB::fromString(cv::Mat&, std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `pangolin::CreatePanel(std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `cv::operator<<(cv::FileStorage&, std::string const&)' /usr/bin/ld: ../lib/libORB_SLAM3.so: undefined reference to `boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::load(std::string&)' collect2: error: ld returned 1 exit status make[3]: *** [CMakeFiles/rgbd_tum.dir/build.make:212:../Examples/RGB-D/rgbd_tum] 错误 1 make[2]: *** [CMakeFiles/Makefile2:1106:CMakeFiles/rgbd_tum.dir/all] 错误 2 make[1]: *** [CMakeFiles/Makefile2:1113:CMakeFiles/rgbd_tum.dir/rule] 错误 2 make: *** [Makefile:560:rgbd_tum] 错误 2
11-18
/usr/bin/ld: CMakeFiles/hallo.dir/src/hallo.cpp.o: in function `main': hallo.cpp:(.text+0x95): undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)' /usr/bin/ld: hallo.cpp:(.text+0x127): undefined reference to `ros::NodeHandle::NodeHandle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)' /usr/bin/ld: hallo.cpp:(.text+0x14c): undefined reference to `ros::console::g_initialized' /usr/bin/ld: hallo.cpp:(.text+0x15c): undefined reference to `ros::console::initialize()' /usr/bin/ld: hallo.cpp:(.text+0x1b5): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::console::levels::Level)' /usr/bin/ld: hallo.cpp:(.text+0x1f8): undefined reference to `ros::console::setLogLocationLevel(ros::console::LogLocation*, ros::console::levels::Level)' /usr/bin/ld: hallo.cpp:(.text+0x204): undefined reference to `ros::console::checkLogLocationEnabled(ros::console::LogLocation*)' /usr/bin/ld: hallo.cpp:(.text+0x25c): undefined reference to `ros::console::print(ros::console::FilterBase*, void*, ros::console::levels::Level, char const*, int, char const*, char const*, ...)' /usr/bin/ld: hallo.cpp:(.text+0x274): undefined reference to `ros::NodeHandle::~NodeHandle()' /usr/bin/ld: hallo.cpp:(.text+0x33d): undefined reference to `ros::NodeHandle::~NodeHandle()' collect2: erro
03-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值