Thanks guys.
I have constructed some code but am getting some errors. I am trying to use
a vector to hold several values but everytime I execute it I get a page
worth of errors. Code below:
po::options_description desc("Available Options");
desc.add_options()
("file", po::value< vector<string> >(), "specify files to search")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("file")) {
cout << "Files selected: " << vm["file"].as< vector<string> >() << "\n";
} else {
cout << "No Files selected.\n";
}
The error is being caused by the following line:
cout << "Files selected: " << vm["file"].as< vector<string> >() << "\n";
Here is the error message:
play.cpp: In function ‘int main(int, char**)’:
play.cpp:24: error: no match for ‘operator<<’ in ‘std::operator<< [with
_Traits = std::char_traits<char>](((std::basic_ostream&)(& std::cout)), ((const char*)"Files selected: "))
<< ((const
boost::program_options::variable_value*)vm.boost::program_options::variables_map::operator[](((const
std::string&)(& std::basic_string(((const char*)"file"), ((const
std::allocator<char>&)((const std::allocator<char>*)(&
std::allocator<char>()))))))))->boost::program_options::variable_value::as
[with T = std::vector, std::allocator > >]()’
/usr/include/c++/4.3/ostream:112: note: candidates are:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&
(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:121: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ios<_CharT, _Traits>&
(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:131: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/include/c++/4.3/ostream:169: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:173: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:177: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(bool) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/bits/ostream.tcc:97: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(short int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:184: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/bits/ostream.tcc:111: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:195: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:204: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long long int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:208: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:213: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:217: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(float) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:225: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(long double) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/ostream:229: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(const void*) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/include/c++/4.3/bits/ostream.tcc:125: note:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT =
char, _Traits = std::char_traits<char>]
.
.
.
2009/8/23 Ovanes Markarian
Hi!
Take a look at boost program_options library:
http://www.boost.org/doc/libs/1_39_0/doc/html/program_options.html
Regards,
Ovanes
On Sun, Aug 23, 2009 at 7:31 PM, Shaolin wrote:
Hi Guys
Below is my current code used to retrieve commandline arguments:
int i = 1;
while (i < argc)
{
if (strcmp(argv[i], "-f") == 0)
{
for (++i; i < argc && strcmp(argv[i], "-s") != 0; ++i) {
filearr.push_back(argv[i]);
}
}
else if (strcmp(argv[i], "-s") == 0)
{
for (++i; i < argc && strcmp(argv[i], "-f") != 0; ++i) {
searchtext = argv[i];
}
}
else
{
++i;
}
}
As you can see, its not very scalable. I am thinking of adding another
feature args but it'll become difficult to manage. Is there anything on
boost which does the same thing albeit with alot less code ?
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users