Boost logo

Boost Users :

Subject: [Boost-users] Boost program option parsing issue.
From: Vivek Anand (vickywindwin_at_[hidden])
Date: 2013-08-19 12:46:06


Hi All,

I am using program option for my program. Here is my code snippet

 string inputFile, outputFile;

/* Populate command line arguments */
    po::options_description desc("Usage: KDMGenerator [OPTIONS]");
    {
        desc.add_options()
            ("help", "prints this message")
            ( "input-file", po::value<string>(&inputFile), "input file
name" )
            ( "output-file", po::value<string>(&outputFile), "output file
name");
    }

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);

    if (vm.count("help") || !vm.size())
    {
        cout <<desc;
        return 0;
    }

    if(vm.count("input-file"))
    {
        cout << "Input file :" << inputFile << '\n';
    }

    if(vm.count("output-file"))
    {
        cout << outputFile << '\n';
    }

The issue I am facing is that if i I call my program without passing value
for input file, something like

./myapp --input-file --output-file out.txt

I get Input file: --output-file

i.e the value "--output-file" get stored in inputFile and
vm.count("output-file") returns zero.

Is this the desired behavior? Is there any workaround for this?

-- 
Vivek,


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