[英]How can I write a version string as a literal (not string) in 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編寫字符串[ 1.7.3.nonRelease ]
,它會注意到,如果只是直接粘貼文本,它將被解釋為列表,因此會引用該字符串以防止出現這種情況。
如果您真的想編寫一個包含一個元素的列表,請這樣做:
config["hints"]["SoftwareRequirement"]["packages"][m_exeName]["version"][0] = versionID;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.