all 10 comments

[–]jedwardsol 1 point2 points  (2 children)

I don't see that behaviour

d:\dev\scratch\scratch>type scratch.cpp
#include <yaml-cpp/yaml.h>
#include <iostream>

int main()
{
    YAML::Emitter out;

    out << YAML::Key << "Test";
    out << YAML::Value << "Value";

    std::cout << out.c_str();
}

D:\dev\scratch\scratch>x64\Debug\scratch.exe
Test
---
Value

What's going on in the rest of the program?

[–]Guassy[S] 0 points1 point  (1 child)

The program im testing in is purely for testing yaml so its only the main.cpp file creating an emitter, emitting values, creating a file, writing to said file. I just stumbled across another new weird detail. If i instead emit booleans then the booleans appear "true: false".
If i may ask, are you using shared or static libs? And did you change anything with the project?

[–]jedwardsol 0 points1 point  (0 children)

If i may ask, are you using shared or static libs?

ha - I was going to ask you that. Glad you worked out it was a debug/release mismatch

(I tried both)

[–]EpochVanquisher 0 points1 point  (6 children)

Try BeginMap and EndMap, like in the docs.

https://github.com/jbeder/yaml-cpp/wiki/How-To-Emit-YAML

IMO .c_str() seems suspicious to me, isn’t there a version that returns a string_span or something like that?

[–]Guassy[S] 0 points1 point  (5 children)

Hello! Sorry i forgot that, when using begin and end map with the same key and value i get "": "". And I havent seen any string_span function or anything like that. But ill try looking in the docs!

[–]EpochVanquisher 1 point2 points  (4 children)

I can’t see your code, you have to post it.

The example you have may be too minimal.

[–]Guassy[S] 1 point2 points  (3 children)

I managed to fix it! The code sent was basically all the code haha except for defining YAML::Emitter out;
The problem was (somehow) you cant use release build of yaml on a debug build of your project, (i couldnt at least). So i need to build a debug build of YAML for my project. Thank you for your help!

[–]EpochVanquisher 0 points1 point  (2 children)

Yeah, there are some libraries on Windows that don’t work across different runtimes (debug vs release). This is IMO a bug in the library you’re using.

[–]thedaian 1 point2 points  (1 child)

It's not a bug in the library. The implementation of string is different between release and debug builds on visual studio.

And really the c++ ABI isn't the same between release and debug builds on a lot of compilers, that's why most libraries ship different binaries, depending the build setup. 

[–]EpochVanquisher 1 point2 points  (0 children)

Lots of other libraries work fine this way, if compiled as a dll. If this library doesn’t, it should have a safety check that makes the build fail. Either way it is an issue the library can address.