Boost程序选项在从命令行读取数据时更改数据(这是Boost中的错误吗?)
boost program options changes data when it reads from command line (is it a bug in boost?)
我在boost::program options中有这段代码:
("output_path,o", po::value< std::string >(&outputPath)->implicit_value(""), "path to where the output should be created.")
和在命令行我有:
-o "C:My DataImagesWithDifferentResolution"
当boost选项用数据填充outputPath时,我在变量中获得此值:
C:My DataImagesWithDifferentResolution"
注意路径末尾的额外引号。
我该如何修复它?
<标题>编辑1要清楚,这是一个bug在增强。我知道在编译代码时应该转义字符串,但这是boost程序选项工作和从命令行提取输入数据的方式。
再解释一下:
我的程序名为testPrg.exe,我正试图以以下方式调用它:
testprg.exe -o "C:My DataImagesWithDifferentResolution"
这是正确的,我的用户应该能够做到这一点。没有必要转义 on命令行。
但是boost程序选项,错误地将最后的"转换成转义值。
测试显示错误的应用程序:
main()
{
po::options_description desc("Allowed options");
std::string outputPath;
desc.add_options()
("output_path,o", po::value< std::string >(&outputPath)->implicit_value(""), "path to where the output should be created.")
;
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm);
std::cout<<outputPath <<std::endl;
}
使用boost 1.58编译cod,并按照上面的说明运行它,并检查输出
标题>这不是Boost.Program_options中的一个bug;它是编译器提供的Microsoft C/c++启动代码的预期行为。也就是说,当"
在argv
中传递到main
时,它已经转化为"
。
摘自Visual Studio 2015参考文档中的解析C命令行参数:
前面带反斜杠的双引号
"
被解释为文字双引号("
)。Command-Line Input | argv[1] | argv[2] | argv[3] -------------------+---------+---------+--------- "ab"c" "\" d | ab"c | | d
一个可能的解决方案可能是调用GetCommandLine
来获取lpCommandLine
并将其传递给split_winmain
(尽管这可能与Microsoft启动代码具有相同的行为)或自己拆分命令行
相关文章:
- boost::asio UDP 广播客户端仅接收"fast"数据包
- 使用 Boost.Spirit 解析具有混合数据类型的 OBJ 文件?
- TCP 服务器的异步读取使用 boost::asio 打印客户端套接字发送的数据
- 如何复制 boost::aligned_storage 对象中的数据?
- boost::asio 不会触发读取处理程序,而 Wireshark 会看到传入的数据
- 如何使用 boost::asio 的 async_read_some() 读取所有可用数据,而无需等待新数据到达?
- boost::asio-async_read_some示例代码没有读取套接字中的所有数据
- boost odeint 中的受控误差步进器是否支持复杂的数据类型?
- boost::asio::async_read 无限循环,接收数据为零字节
- 如何将 JSON 键值(我使用 cpp boost 解析)存储在相关数据结构中?
- "非静态数据成员之前需要构造函数" - 我是否使用"boost::variant"
- boost::asio 以async_read复制输入数据
- 使用 boost::p ython 将数据缓冲区放入C++中
- C 使用BOOST.ASIO和BEAST库中的身体发送数据
- Boost Asio网络发送/接收是否具有任何形式的数据完整性保证
- 插座无法接收数据?客户使用boost.asyio库编写.服务器用Python编写
- 使用标准库或Boost库从一组数据中计算直方图
- 数据集(和样本)何时在 boost::test 中销毁?
- 使用 boost zlib 从 std::vector 中的文件中读取压缩的 zraw 数据
- 了解 UDP 数据包大小限制的 TCP 数据包大小限制以及它在 boost::asio 编程级别的含义