Boost logo

Boost Users :

Subject: Re: [Boost-users] Program Options and Filesystem ifstream
From: Sergiu Dotenco (sergiu.dotenco_at_[hidden])
Date: 2015-08-18 16:20:42


On 8/18/2015 5:38 PM, Scott Morgan wrote:
> Having a problem getting the following to compile under a Linux system
> (Mint 17.2, boost 1.54). It works okay with MSVC2010 and boost 1.57 though.
>
> **begin: main.cpp**
> #include <boost/filesystem/fstream.hpp>
> namespace fs = boost::filesystem;
> #include <boost/program_options.hpp>
> namespace po = boost::program_options;
>
> void test(fs::path& cfg_path, po::options_description& cfg_desc,
> po::variables_map& options)
> {
> po::store(po::parse_config_file(fs::ifstream(cfg_path), cfg_desc,
> true), options);
> }
> **end: main.cpp**
>
> Is this just a problem with 1.54's version of filesystem and/or program
> options?
>
> Scott
>
>
> **begin: GCC output**
> main.cpp: In function ‘void test(boost::filesystem::path&,
> boost::program_options::options_description&,
> boost::program_options::variables_map&)’:
> main.cpp:8:72: error: no matching function for call to
> ‘parse_config_file(boost::filesystem::ifstream,
> boost::program_options::options_description&, bool)’
> po::store(po::parse_config_file(fs::ifstream(cfg_path), cfg_desc,
> true), options);
> ^
> main.cpp:8:72: note: candidates are:
> In file included from /usr/include/boost/program_options.hpp:17:0,
> from main.cpp:3:
> /usr/include/boost/program_options/parsers.hpp:185:5: note:
> boost::program_options::basic_parsed_options<charT>
> boost::program_options::parse_config_file(std::basic_istream<charT>&,
> const boost::program_options::options_description&, bool) [with charT =
> char]
> parse_config_file(std::basic_istream<charT>&, const
> options_description&,
> ^

Your are trying to pass a temporary to a reference parameter, which is
wrong.

Try instead:

fs::ifstream in(cfg_path);
po::store(po::parse_config_file(in, cfg_desc, true), options);


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net