Boost logo

Boost :

From: Chris Weed (chrisweed_at_[hidden])
Date: 2005-12-08 16:11:33


Hi,
I would like to have the program_options functions parse a
boost::filesystem path.

For example something like the following code. However, this doesn't
seem to work. The error seems to suggest the problem is a lack of
operator >> for path.

Is it possible to make this work?

  namespace po = boost::program_options;
  namespace fs = boost::filesystem;
  po::options_description generic("Allowed options");
  generic.add_options()
    ("help", "produce help message")
    ("output-path,o",po::value<fs::path>(), "output path")
    ("input-file", po::value<fs::path>(), "input file")
  ;

  po::positional_options_description p;
  p.add("input-file", -1);

  po::variables_map vm;
  po::store(po::command_line_parser(argc, argv).
            options(generic).positional(p).run(), vm);
  po::notify(vm);

  fs::path input_path;
  if(vm.count("input-file"))
  {
    input_path = vm["input-file"].as<fs::path>();
  }

Error:
boost_1_33_0/boost/lexical_cast.hpp: In member function 'bool
boost::detail::lexical_stream<Target,
Source>::operator>>(InputStreamable&) [with InputStreamable =
boost::filesystem::path, Target = boost::filesystem::path, Source =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>]':
boost_1_33_0/boost/lexical_cast.hpp:221: instantiated from 'Target
boost::lexical_cast(const Source&) [with Target =
boost::filesystem::path, Source = std::basic_string<char,
std::char_traits<char>, std::allocator<char> >]'
../radarvision/MIDAS/build/boost_1_33_0/boost/program_options/detail/value_semantic.hpp:83:
  instantiated from 'void
boost::program_options::validate(boost::any&, const
std::vector<std::basic_string<charT, std::char_traits<charT>,
std::allocator<_T2> >, std::allocator<std::basic_string<charT,
std::char_traits<charT>, std::allocator<_T2> > > >&, T*, long int)
[with T = boost::filesystem::path, charT = char]'
boost_1_33_0/boost/program_options/detail/value_semantic.hpp:151:
instantiated from 'void boost::program_options::typed_value<T,
charT>::xparse(boost::any&, const std::vector<std::basic_string<charT,
std::char_traits<charT>, std::allocator<_T2> >,
std::allocator<std::basic_string<charT, std::char_traits<charT>,
std::allocator<_T2> > > >&) const [with T = boost::filesystem::path,
charT = char]'
main.cpp:32: instantiated from here
boost_1_33_0/boost/lexical_cast.hpp:165: error: no match for
'operator>>' in
'((boost::detail::lexical_stream<boost::filesystem::path,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>*)this)->boost::detail::lexical_stream<boost::filesystem::path,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>::stream >> output'
/atech/gcc-4.0.0/lib/gcc/sparc-sun-solaris2.8/4.0.0/../../../../include/c++/4.0.0/istream:131:
note: candidates are: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT,
_Traits>::operator>>(std::basic_istream<_CharT, _Traits>&
(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]
/atech/gcc-4.0.0/lib/gcc/sparc-sun-solaris2.8/4.0.0/../../../../include/c++/4.0.0/istream:134:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT,
_Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]

Thanks,
Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk