Learn more. Asked 10 years, 8 months ago. Active 5 years, 4 months ago. Viewed 7k times. On command line '--coordinate 1 2' works. Improve this question. Regel Regel 1 1 gold badge 5 5 silver badges 11 11 bronze badges. If you do, you risk having memory leaks. Add a comment.
Active Oldest Votes. In your configuration file, put each element of your vector on a different line. Improve this answer.
Adam Hunt Adam Hunt 1 1 silver badge 6 6 bronze badges. Community Bot 1 1 1 silver badge. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back To use Boost. An object of this type can be written to a stream such as std::cout to display an overview of available command-line options.
The string passed to the constructor gives the overview a name that acts as a title for the command-line options. You call this function to describe each command-line option. Instead of calling this function for every command-line option, Example It uses the overloaded operator operator , which you can call to pass the required data to define a command-line option. This operator returns a reference to the same proxy object, which allows you to call operator multiple times.
The first command-line option is --help. You set --help on the command line or omit it. You can specify short names for command-line options. A short name must consist of just one letter and is set after a comma. Now the help can be displayed with either --help or -h.
Besides --help , two more command-line options are defined: --pi and --age. Both --pi and --age expect to be set to a value. Thus, the command-line option --age expects an integer and --pi expects a floating point number. That function is then called with the value of the command-line option. In Example After all command-line options have been defined, you use a parser. This function takes argc and argv , which define the command line, and desc , which contains the option descriptions.
For example, you can call count to check whether a certain command-line option has been used and is stored in the container. You can get the object of type boost::any from the member function value. This member function converts the value of a command-line option to the type passed as a template parameter.
Be sure the type you pass to as matches the type of the command-line option. For example, Example You can start Example Here is one example:.
In this case Pi: 3. The output is now On age: 29 and Age: There is no output for --pi because the program uses else if statements that only display the value set with --pi if --age is not set. As you can see, the help can be shown in two different ways because a short name for that command-line option was defined.
For --pi the default value is displayed. The command-line options and their descriptions are formatted automatically.
The exception is caught, and an error message is written to standard output. However, there are some notable differences. In that case, pi is set to 3. This stores the value of a command-line option in a variable.
Of course, the value is still available in the container vm. In fact, you can pass multiple phone numbers on the command line. For example, the following command line starts the program with the phone numbers and You can also pass multiple phone numbers by repeating the --phone option, as shown in the following command line:. In this case, both phone numbers, and , are parsed.
The call to composing makes it possible to use a command-line option multiple times — the values are composed. You need to use a container to store multiple phone numbers. While Example You must call options to pass the definition of command-line options to the parser.
0コメント