|
Boost Users : |
Subject: Re: [Boost-users] commandline args
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-08-23 22:42:04
On Sun, Aug 23, 2009 at 8:20 PM, Diederick C.
Niehorster<dcnieho_at_[hidden]> wrote:
>> The same way that you would stream any normal vector:
>> vector<string> &files = vm["file"].as< vector<string> >();
>> vector<string>::const_iterator iter = files.begin();
>> cout << "Files selected: ";
>> for(;iter!=files.end();++iter)
>> {
>> cout << *iter << ";";
>> }
>> cout << "\n";
>>
>
>> Consequently, if you have Boost trunk installed, then you could do
>> this as well since it does support streaming vectors:
>> #include <boost/spirit/include/karma.hpp>
>> using namespace boost::spirit::karma;
>> using namespace boost::spirit::ascii;
>>
>> generate(cout, "Files selected: " << (*char_)%';' << eol,
>> vm["file"].as< vector<string> >());
>
> Or you could simply do:
> #include <boost/foreach.hpp>
> cout << "Files selected: ";
> BOOST_FOREACH(string& sFile, vm["file"].as< vector<string> >())
> cout << sFile.c_str() << endl;
That is assuming you wanted an endl at the end of each name, a usual
delimiter is something like ';' or so, so this instead:
cout << "Files selected: ";
BOOST_FOREACH(string& sFile, vm["file"].as< vector<string> >())
cout << sFile.c_str() << ";";
cout << "\n";
Although the karma version that Hartmut posted is still the fastest
way to do it (in terms of execution speed):
generate(sink,
"Files selected: " << string % ';' << eol,
vm["file"].as< vector<string> >());
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