using filesystem path with program_options

]': 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]'
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> 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

Chris Weed wrote:
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?
Yes, you have two approaches. 1. Specify a custom way to parse fs::path to Boost.program_options See http://boost.org/doc/html/program_options/howto.html#id2716150 for an example. 2. Convince Beman Dawes, the author of Boost.Filesystem, that adding operator>> for paths is a good idea. Personally, I don't see any reason why it should not work -- if I want to save/load something containing boost::fs::path, working operator>> would be a plus. - Volodya

Thanks, I also noticed that the function call "validators::check_first_occurence(v);" is misspelled in the example. occurrence should have 2 'r's Chris On 12/9/05, Vladimir Prus <ghost@cs.msu.su> wrote:
Chris Weed wrote:
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?
Yes, you have two approaches.
1. Specify a custom way to parse fs::path to Boost.program_options See http://boost.org/doc/html/program_options/howto.html#id2716150 for an example.
2. Convince Beman Dawes, the author of Boost.Filesystem, that adding operator>> for paths is a good idea. Personally, I don't see any reason why it should not work -- if I want to save/load something containing boost::fs::path, working operator>> would be a plus.
- Volodya
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Vladimir Prus <ghost@cs.msu.su> writes:
[snip]
2. Convince Beman Dawes, the author of Boost.Filesystem, that adding operator> for paths is a good idea. Personally, I don't see any reason why it should not work -- if I want to save/load something containing boost::fs::path, working operator>> would be a plus.
That would be reasonable provided that the input and output strings are in the native path format. -- Jeremy Maitin-Shepard
participants (3)
-
Chris Weed
-
Jeremy Maitin-Shepard
-
Vladimir Prus