Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参数命令行解析问题 #2

Open
yuanziran opened this issue Apr 7, 2024 · 1 comment
Open

参数命令行解析问题 #2

yuanziran opened this issue Apr 7, 2024 · 1 comment

Comments

@yuanziran
Copy link

代码中没有设置位置参数,为什么他会报位置参数错误
Util::argparser parse("ximage");
parse.set_program_name("ximage2d")
.add_help_option()
.add_option("-i", "--input", "input file (*.bin).")
.add_option("-x", "--xdim", "input xdim.")
.add_option("-y", "--ydim", "input ydim.")
.add_option("-X", "--xbegin", "xbegin default 0.0 ", 0.0)
.add_option("-Y", "--ybegin", "ybegin default 0.0 " , 0.0)
.add_option("", "--xinterval", "xinterval default 1.0 ", 1.0)
.add_option("", "--yinterval", "yinterval default 1.0 ", 1.0)
.add_optionstd::string("-t", "--title", "chart title default ",
"")
.add_option("-W", "--width", "window width default value 400", 400)
.add_option("-H", "--height", "window height default value 400", 400)
.parse(argc, argv);

程序运行结果
.\ximage2d.exe -i .\demo1-1911 -x 1 -y 100
(parse error) position argument number missmatching, give 3, but need 0
uncaptured command line arguments:
.\demo1-1911
1
100

@0382
Copy link
Owner

0382 commented Apr 7, 2024

不带模板的add_option默认是bool类型选项,后面不接参数,命令行里有和没有来标识true/false,所以这里的.\demo1-1991, 1, 100都没有用到。add_option("-X", "--xbegin", "xbegin default 0.0 ", 0.0)由于最后一个参数0.0匹配上了add_option<double>,这是接受参数的。我还是建议明确写add_option<int>, add_option<double>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants