Created
March 10, 2021 01:05
-
-
Save kerrickstaley/1e1e7c56eede6015b99f4ca47912f7d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <yaml-cpp/yaml.h> | |
#include <iostream> | |
#include <string> | |
int main() { | |
YAML::Node node = YAML::Load(R"foo( | |
a: | |
b: c | |
d: 1 | |
)foo"); | |
// Method without BeginSeq | |
YAML::Emitter emitter1; | |
emitter1 << YAML::DoubleQuoted << YAML::Flow << node; | |
std::string out1(emitter1.c_str()); | |
std::cout << "Output without BeginSeq:\n" << out1 << '\n'; | |
// Approach using BeginSeq | |
YAML::Emitter emitter2; | |
emitter2 << YAML::DoubleQuoted << YAML::Flow << YAML::BeginSeq << node; | |
std::string out2(emitter2.c_str() + 1); // Strip leading [ character | |
std::cout << "Output with BeginSeq:\n" << out2 << '\n'; | |
} | |
/* | |
On my system, this program outputs: | |
Output without BeginSeq: | |
"a": | |
"b": "c" | |
"d": "1" | |
Output with BeginSeq: | |
{"a": {"b": "c", "d": "1"}} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment