Adam Nielsen wrote:
Hi everyone,
I'm writing a program that needs to know the order that parameters are supplied in, but I can't find anything in the docs about this.
For example, a program to work with .zip files might work like this:
zip --rename=one.bin:alpha.bin --add=one.bin --rename=one.bin:beta.bin
The initial --rename would need to be acted upon first, before --add (otherwise one.bin would get overwritten) and likewise the last --rename must be acted upon after --add, otherwise the wrong file (or no file) would be renamed. If I use normal string vectors the order of the parameters will be lost so this won't work.
Is this sort of parsing possible with program_options, or will I need to resort to writing my own command-line parsing code?
The parse_command_line function returns vector<options> which is accurate representation of what was found on the command line -- in particular: - the order of options is the same as on command line - if there are multiple occurrences of the same option, those are not collapsed and stay separate. Does this help? - Volodya