yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

SetIntBase() does not seem to work

Open dannypike opened this issue 5 years ago • 2 comments

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

dannypike avatar Oct 01 '18 06:10 dannypike


#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;
}

ljluestc avatar Jan 05 '24 20:01 ljluestc

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? :)

dannypike avatar Jan 06 '24 09:01 dannypike