Christine Zhu
Christine Zhu

Reputation: 87

boost::bad_any_cast: failed conversion using boost::any_cast

I am using boost V1.53 program_option like this..

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include "linked_list.h"
#include <map>
#include "stdList.h"
#include "vector.h"
#include "set.h"
#include "AVL.h"
#include <boost/program_options.hpp>


using namespace std;
namespace po = boost::program_options;

int main(int argc ,char* argv[])
{
    ifstream dictionary, text;
    ofstream output;
    string dictionaryFile, textFile, outputFile,dtStructure;


    po::options_description desc("Allowed options");
    desc.add_options()
    ("DataStructure, s", po::value<string>()->required(), "Specify datastructure")
    ("Dictionary, d", po::value<string>()->required(), "Specify dictionary")
    ("TextFile, t", po::value<string>()->required(), "Specify textfile")
    ("Output, o", po::value<string>()->required(), "Specify output file");

try
{

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);
    const string dtStruct=vm["DataStructure"].as<string>();
    cout <<"data is " <<dtStruct <<endl;


}
catch (const exception &e)
{
    cerr <<e.what()<<endl;
    return EXIT_FAILURE;
}
------and more code------

however, when i compiled .\output --DataStruture a.dat --Dictionary dict --TextFile small --Output. file

it shows a boost::bad_any_cast: failed conversion using boost::any_cast

any idea why?

Upvotes: 0

Views: 2208

Answers (1)

Richard Hodges
Richard Hodges

Reputation: 69892

The code is correct - you spelled the option wrongly on the command line.

Upvotes: 1

Related Questions