|
Boost Users : |
Subject: Re: [Boost-users] commandline args
From: Shaolin (shaolinfinest_at_[hidden])
Date: 2009-08-24 11:24:56
OvermindDL1
The code you specifed to retrieve several values for one param doesn't
work:
po::positional_options_description pd;
pd.add("file", -1);
I tried
value< vector<string> >()->multitoken()
which did the trick, however all the text it treated as one string when each
word should be placed into its only place in the vector.
2009/8/24 Hartmut Kaiser <hartmut.kaiser_at_[hidden]>
> > Yup, now it works.
>
> Good.
>
> > For reference, I got rid of the duplicated bk::eol also by using the
> > folloing code:
> >
> > bk::generate(ostream_iterator<char>(cout),
> > "Command line options not recognized:\n" <<
> > (" \"" << ba::string << '"' << bk::eol) % "",
> > vsTest);
>
> If you don't need any separators in between the list items you could write:
>
> bk::generate(ostream_iterator<char>(cout),
> "Command line options not recognized:\n" <<
> *(" \"" << ba::string << '"') << bk::eol,
> vsTests);
>
> (which is the equivalent of a Kleene Star).
>
> BTW, Karma has a different API allowing to directly integrate the code
> above with output streams:
>
> cout << karma::format(
> *(" \"" << ascii::string << '"') << eol
> , vsTest
> );
>
> where format is a std::stream manipulator.
>
> Regards Hartmut
>
> >
> > Not putting an empty char array after the modulus operator would be
> > invalid C++ and is thus required.
> >
> > Thanks again,
> > Best,
> > Diederick
> >
> > On Mon, Aug 24, 2009 at 1:45 PM, Diederick C.
> > Niehorster<dcnieho_at_[hidden]> wrote:
> > > Dear OvermindDL1,
> > >
> > > That solves the issue then, I'm using Boost 1.39 ;)
> > >
> > > Let me try trunk, all should work fine then. I have seen the other
> > > thread in which the location of sprit v2.1's doc were disclosed,
> > > however i didn't connect those threads for some reason.
> > >
> > > Thanks again!
> > >
> > > Best,
> > > Diederick
> > >
> > > On Mon, Aug 24, 2009 at 1:36 PM, OvermindDL1<overminddl1_at_[hidden]>
> > wrote:
> > >> On Sun, Aug 23, 2009 at 11:20 PM, Diederick C.
> > >> Niehorster<dcnieho_at_[hidden]> wrote:
> > >>> That also gave me compilation errors:
> > >>>
> > >>> ..\Dependency\boost\boost/spirit/home/karma/generate.hpp(72) :
> > error
> > >>> C2664: 'boost::mpl::assertion_failed' : cannot convert parameter 1
> > >>> from 'boost::mpl::failed ************(__thiscall
> > >>> boost::spirit::karma::generate::error_invalid_expression::*
> > >>> ***********)(Expr)' to 'boost::mpl::assert<false>::type'
> > >>>
> > >>> ..\Dependency\boost\boost/spirit/home/karma/generate.hpp(76) :
> > error
> > >>> C2039: 'generate' : is not a member of
> > >>> 'boost::proto::exprns_::expr<Tag,Args,Arity>'
> > >>>
> > >>> Below, please find a minimal example.
> > >>> Thank you for your continued help!
> > >>>
> > >>> Best,
> > >>> Dee
> > >>>
> > >>> ---
> > >>> #include <vector>
> > >>> #include <string>
> > >>> #include <iostream>
> > >>> using namespace std;
> > >>> #include <boost/spirit/include/karma.hpp>
> > >>> namespace bk = boost::spirit::karma;
> > >>> namespace ba = boost::spirit::ascii;
> > >>>
> > >>>
> > >>> int main()
> > >>> {
> > >>> vector<string> vsTest;
> > >>> vsTest.push_back("test");
> > >>> vsTest.push_back("t2");
> > >>> vsTest.push_back("t3");
> > >>>
> > >>>
> > >>> bk::generate(ostream_iterator<char>(cout),
> > >>> "Command line options not recognized:\n" <<
> > >>> (" \"" << ba::string % ("\"" << bk::eol)) << "\"" <<
> > bk::eol,
> > >>> vsTest);
> > >>>
> > >>>
> > >>> bk::generate(ostream_iterator<char>(cout),
> > >>> "Command line options not recognized:\n" <<
> > >>> ('\"' << ba::string << '\"') % bk::eol << bk::eol,
> > >>> vsTest);
> > >>>
> > >>> return 0;
> > >>> }
> > >>> ---
> > >>>
> > >>
> > >> This is what I get when I compile with your test:
> > >> 1>------ Build started: Project: pure_testing, Configuration:
> > Release
> > >> Win32 ------
> > >> 1>Compiling...
> > >> 1>main.cpp
> > >> 1>using native typeof
> > >> 1>Linking...
> > >> 1>Generating code
> > >> 1>Finished generating code
> > >> 1>Embedding manifest...
> > >> 1>Build Time 0:27
> > >> 1>Build log was saved at
> > >> "file://r:\Programming_Projects\pure_testing\Release\BuildLog.htm"
> > >> 1>pure_testing - 0 error(s), 0 warning(s)
> > >> ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
> > ==========
> > >>
> > >> Looks like it works perfect to me. You are using Boost Trunk like I
> > >> stated in my first post in this thread, right?
> > >>
> > >> You should still use this grammar though, it is the best:
> > >> bk::generate(ostream_iterator<char>(cout),
> > >> "Command line options not recognized:\n" <<
> > >> (" \"" << ba::string << '\"') % bk::eol
> > >> ,vsTest);
> > >> And yes, I confirmed it compiles and runs as you want.
> > >> _______________________________________________
> > >> Boost-users mailing list
> > >> Boost-users_at_[hidden]
> > >> http://lists.boost.org/mailman/listinfo.cgi/boost-users
> > >>
> > >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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