yaml-cpp
yaml-cpp copied to clipboard
SetIntBase() does not seem to work
I would like int
values to be output in hex format, but calling:
emitter.SetIntBase(Hex);
appears to have no effect on anything. There does not seem to be an overload of Write()
that uses std::hex
.
Dan
#include <iostream>
#include "yaml-cpp/yaml.h"
#include <sstream>
int main() {
YAML::Emitter out;
int hexValue = 0x10; // Example integer value in hexadecimal
// Convert the integer to a hexadecimal string
std::stringstream hexStringStream;
hexStringStream << std::hex << hexValue;
std::string hexString = hexStringStream.str();
// Emit the hexadecimal string
out << YAML::BeginMap;
out << YAML::Key << "hexValue";
out << YAML::Value << hexString;
out << YAML::EndMap;
assert(out.good());
std::cout << out.c_str();
return 0;
}
Thanks for the code snippet on how to do the conversion myself, but my point is that it would be nice if the function did what I believe it was designed to do, so that I don't have to.
Otherwise, what is a utility library for? :)