c++ - 如何在 YAML-CPP 中将版本字符串写为文字(不是字符串)?
问题描述
我正在尝试编写以下信息:
hints:
SoftwareRequirement:
packages:
ApplicationName:
version: [ 1.7.3.nonRelease ]
我正在使用以下代码部分:
std::string m_exeName = # I get this from my CMakeLists file
std::string versionID = # I get this from my CMakeLists file
YAML::Node hints = config["hints"];
config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"] = "[ " + versionID + " ]";
它让我得到以下信息:
hints:
SoftwareRequirement:
packages:
ApplicationName:
version: "[ 1.7.3.nonRelease ]"
有没有办法让方括号内的引号或完全删除它们?这符合通用工作流语言(CWL) 标准。
可能与这个问题有关。
编辑(从答案添加结果):
带着这个去:
config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"][0] = versionID
结果:
hints:
SoftwareRequirement:
packages:
ApplicationName:
version:
- 1.7.3.nonRelease
With 是一个有效的 CWL。
解决方案
[]
是序列的 YAML 语法;所以如果你想写
[ 1.7.3.nonRelease ]
那么你正试图用一个元素编写一个序列1.7.3.nonRelease
。当您告诉 yaml-cpp 写入 string[ 1.7.3.nonRelease ]
时,它注意到如果它只是直接粘贴文本,它将被解释为一个列表,因此它引用了该字符串以防止这种情况发生。
如果你真的想写一个包含一个元素的列表,那就这样吧:
config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"][0] = versionID;
推荐阅读
- html - HTML 如何正确使用工具提示
- linux - 为什么我们或 || Bash 中的任何条件,例如“iw dev interface_name del || true”?
- python - 尝试做线性线性回归分类器给我“ValueError:预期的二维数组,而不是一维数组
- python - 从组标签中获取字符串文本
- node.js - Docker-compose 使 2 个微服务(前端+后端)通过 http 请求相互通信
- java - 多个主屏幕小部件android的问题
- excel - 将数组传输到文本文件的最快方法
- python - 如何将工作从文件读取到线程?
- excel - 如何将筛选的行选择设置为范围
- ios - 如何正确格式化字体?