获取 boost::p rogram_options 将输入视为常量字符*而不是 std::string
getting boost::program_options to treat input as const char* instead of std::string
class Foo {};
Foo foo;
namespace po = boost::program_options;
boost::program_options::options_description desc("Allowed options")
desc.add_options()
("foo", po::value<Foo>(&foo));
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
以上最终将尝试从 std::string& 到 Foo & 进行lex_cast
有没有办法让它从 const char*& 到 Foo & 进行lex_cast?
谢谢!
您可以通过
为 Foo
定义 istream 运算符来处理此问题:
std::istream& operator>>(std::istream &input_stream, Foo &foo) {
// read from input_stream into foo...
// if read fails, set failbit in input_stream...
return input_stream;
}
相关文章:
- 多字符常量警告
- const_cast<字符 *>(字符* 常量) 不是左值?
- 常量字符数组模板与字符常量* 函数重载
- 如何检查字符常量是否符合ASCII
- 从字符串数组转换为字符* 常量
- 字符常量或字符串常量
- 字符常量数组为空,即使已为其赋值 [C++]
- 如何创建 ' 字符常量
- 如何编写完全可移植的 4 字节字符常量的编译时初始化
- 我得到以下错误:[警告]多字符字符常量
- C++错误:警告:多字符字符常量/a用于用法
- 字符常量和函数名称的 sizeof() 背后的逻辑
- 如何在 C 中将多字符常量转换为整数
- C++ wifstream:不兼容的字符常量*,wchar_t康斯特*类型
- 不允许从"常量无符号字符*常量*"到"常量字符*常量*"static_cast
- 修改字符 *常量字符串
- 为什么字符常量/文字不能为空?
- C++字符 * 常量与字符 *,为什么有时一个有时另一个
- 警告多字符字符常量 [-Wmultichar]
- 开关语句多字符常量