尝试使用 yaml-cpp 读取字符串值时获取 YAML::TypedBadConversion
我一直有一个错误,我不明白为什么会得到它。当尝试读取以下文件 example.yaml
时:
BFS_power:
graph: power.graph
type: METIS
BFS_avg:
graph: DEFAULT
type: whatever
使用以下最小示例:
YAML:Node Instances = YAML::LoadFile(instancesFile);
std::cout << Instances["BFS_power"]["graph"].as<std::string>() << std::endl;
导致以下错误:
terminate called after throwing an instance of 'YAML::TypedBadConversion<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >'
what(): bad conversion
执行 std::cout <<实例["BFS_power"]["graph"] << std::endl;
将打印 power.graph
的正确值,因此我知道该文件正在被读取。但是,Instances["BFS_power"]["graph"]
生成的对象是 Node 而不是字符串。
我是否缺少读取字符串所必需的东西?
I have been having a error that I can't figure out why a getting it. When trying to read the following file example.yaml
:
BFS_power:
graph: power.graph
type: METIS
BFS_avg:
graph: DEFAULT
type: whatever
With the following minimal example:
YAML:Node Instances = YAML::LoadFile(instancesFile);
std::cout << Instances["BFS_power"]["graph"].as<std::string>() << std::endl;
Causes following error:
terminate called after throwing an instance of 'YAML::TypedBadConversion<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >'
what(): bad conversion
Doing std::cout << Instances["BFS_power"]["graph"] << std::endl;
will print the correct value of power.graph
, so I know that the file is being read. However, the object resulting from Instances["BFS_power"]["graph"]
is Node not a string.
Is there something that I am missing that is necessary to read strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从测试来看,如果您首先将其保存在变量中,它显然可以工作。所以
不起作用。但
确实有效。
From testing it apparently works if you are saving it in a variable first. So
doesn't work. But
does work.