<boost> 读取路径下文件

代码:

#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
 
int main ()  
{
    boost::filesystem::path path_pwd = boost::filesystem::current_path();
    boost::filesystem::path path_cfg = path_pwd.parent_path();
    path_cfg /= "/cfg/mycfg.cfg";
 
    std::cout << "cfg path : " << path_cfg.string() << std::endl;
 
    return 0;
}

设置LD_LIBRARY_PATH:

vim .bash_profile
export BOOST_HOME="/root/boost_1_75_0_build"                                                                                                                           
export LD_LIBRARY_PATH=${BOOST_HOME}/lib:$LD_LIBRARY_PATH
source .bash_profile

编译:

g++ 00_cfg_file.cpp -I/root/boost_1_75_0_build/include -L/root/boost_1_75_0_build/lib -lboost_filesystem

执行结果:

cfg path : /root/c++_study/cfg/mycfg.cfg
posted @ 2021-03-22 11:33  kouei_kou  阅读(626)  评论(0)    收藏  举报