我正在使用boost V1.53 program_option ..
#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------
然而,当我编译 。\ output --DataStruture a.dat --Dictionary dict --TextFile small --Output。文件
它显示了boost :: bad_any_cast:使用boost :: any_cast
转换失败任何想法为什么?
答案 0 :(得分:1)
代码是正确的 - 您在命令行上错误地拼写了选项。