I'm new to using external libraries and after some trouble with RapidJSON, I thought I try nlohmann's json library, which is supposed to be super easy to use.
I started a new console project in Visual Studio 2022 and copied the nlohmann
directory within include
folder, just like I did with RapidJSON. I then copied the example code:
#include <iomanip>
#include <iostream>
#include "nlohmann/json.hpp"
using json = nlohmann::json;
int main() {
// a valid JSON text
auto valid_text = R"( { "numbers": [1, 2, 3] } )";
// an invalid JSON text
auto invalid_text = R"( { "strings": ["extra", "comma", ] } )";
std::cout << std::boolalpha << json::accept(valid_text) << ' '
<< json::accept(invalid_text) << '\n';
}
However, I get a bunch of errors:
Error (active) E1696 cannot open source file "nlohmann/adl_serializer.hpp"
Error (active) E1696 cannot open source file "nlohmann/byte_container_with_subtype.hpp"
Error (active) E1696 cannot open source file "nlohmann/detail/conversions/from_json.hpp"
...
When I go to the top of the code and start #include "nlohmann/a
, IntelliSense does suggest the file (adl_serializer.hpp
in this case), so VS is aware of the copied files. Still, the code does not compile and the line
using json = nlohmann::json;
also gives me the error:
"E0276 name followed by '::' must be a class or namespace name"
What can I do to make this work?
Thank you in advance!