0

On this code I get the enourmous error

static void ParseTheCommandLine(int argc, char *argv[])
{
int count;
int seqNumber;

namespace po = boost::program_options;

std::string appName = boost::filesystem::basename(argv[0]);

po::options_description desc("Generic options");
desc.add_options()
("version,v", "print version string")
("help", "produce help message")
("sequence-number", po::value<int>(&seqNumber)->default_value(0), "sequence number")
("pem-file", po::value< vector<string> >(), "pem file")
;

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

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

if (vm.count("pem file"))
{
    cout << "Pem files are: "
         << vm["pem-file"].as< vector<string> >() << "\n";
}

cout << "Sequence number is " << seqNumber << "\n";

exit(1);

../../../FIXMarketDataCommandLineParameters/FIXMarketDataCommandLineParameters.hpp|98|error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits](((std::basic_ostream >&)(& std::cout)), ((const char*)"Pem files are: ")) << ((const boost::program_options::variable_value*)vm.boost::program_options::variables_map::operator[](((const std::string&)(& std::basic_string, std::allocator >(((const char*)"pem-file"), ((const std::allocator&)((const std::allocator*)(& std::allocator()))))))))->boost::program_options::variable_value::as with T = std::vector, std::allocator >, std::allocator, std::allocator > > >’|

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
user1676605
  • 1,337
  • 3
  • 13
  • 21

1 Answers1

3

Vectors don't implement ostream & operator<<(std::ostream &).

You should probably do:

cout << "Pem files are: ";
for (auto & x : vm["pem-file"].as< vector<string> >())
    cout << x << "\n";
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • It is part of the tutorial http://www.boost.org/doc/libs/1_52_0/doc/html/program_options/tutorial.html#id2607140 – user1676605 Nov 17 '12 at 16:58
  • @user1676605: boost tutorials may have bugs. – Yakov Galka Nov 17 '12 at 17:10
  • 1
    gotcha thanks. I solved it by template < class T > std::ostream& operator << (std::ostream& os, const std::vector& v) { os << "["; for (typename std::vector::const_iterator ii = v.begin(); ii != v.end(); ++ii) { os << " " << *ii; } os << "]"; return os; } – user1676605 Nov 17 '12 at 17:18