关于 c:如何使用 yaml-cpp 发出不带引号的字符串? | 珊瑚贝

How to emit a string without quotes using yaml-cpp?


我知道默认情况下 yamp-cpp 发出不带引号的字符串,但是,如果字符串中有括号,它总是用双引号发出。

1
2
3
4
YAML::Emitter out;
// …
const std::string myStr =“[0, 0, 1]”
out << myStr;

在上面的示例中,当我想要 [0, 0, 1]

时,我得到了文件:”[0, 0, 1]”

你知道怎么解决吗?

谢谢!


yaml-cpp 引用您的字符串的原因是,如果没有,您将发出一个序列,而不是一个标量。如果你想发出序列 [0, 0, 1],那么你可以这样做:

1
out << YAML::BeginSeq << 0 << 0 << 1 << YAML::EndSeq;

但是您根本不能将文本 [0, 0, 1] 作为纯标量发出,因为它不是!


你可以试试这个:

1
2
3
4
YAML::Emitter out;
// …
const std::string myStr =“[0, 0, 1]”
out << YAML::Load(myStr);

或者这个:

1
out.WriteStreamable(myStr);

来源:https://www.codenong.com/24684422/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9300.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?