【问题标题】:Using boost program options under Visual Studio MSVC 14.0 Assertion failed在 Visual Studio MSVC 14.0 下使用 boost 程序选项断言失败
【发布时间】:2018-12-01 19:16:19
【问题描述】:

我在 MSVC 14.0 下编译了 Boost 1.66。我正在尝试将在 Boost on Linux 下运行良好的现有项目移植到 Visual Studio。

那是失败的代码:

options.add_options()
            ("help", "Produce help message")
            ("config-file,c", po::value<string>(&config_file_path)->default_value("config.xml"), "Configuration file path")
            ("port,p", po::value<int>(&html_port)->default_value(7999), "HTTP Server port")
            ("html_root,hr", po::value<string>(&html_root)->default_value("."), "Directory root for HTML page");

使用以下断言:

Assertion failed: n == name.size()-2, file libs\program_options\src\options_description.cpp, line 177

有什么建议吗?

【问题讨论】:

    标签: c++ boost boost-program-options


    【解决方案1】:

    我认为选项短名称(逗号后)应该是单个字符,即,hr" 应该是,r"

    【讨论】:

    • 谢谢。确实这就是问题所在。我没有想到,因为它适用于 ubuntu,也适用于 mingw64 下的 windows。
    • 另外,你能告诉我options.add_options() ("help", "Produce help message") 是如何有效的 C++ 语法吗?我不明白。
    • @FakherMokadem options.add_options() 返回对带有重载 operator () 的对象的引用,该对象接受两个参数,依此类推。
    猜你喜欢
    • 2013-01-20
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多