-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatible Pointer Type #1196
Comments
The library does not convert into pointers, but rather returns a pointer to the container used internally. Arrays are stored as |
@nlohmann so then what would be the best way to read this char array out of the file with nlohman json and into a char array or is there one aside from reading it as a string I mean. |
Can you give a precise example? |
I mean I have a Json array of directions for a pet project text adventure game so |
OK. Assuming std::ifstream i("input.json");
json j = json::parse(i);
for (auto& el : j["Directions"])
{
std::string dir1 = el; // access string copy
std::string& dir2 = el.get_ref<std::string&>(); // access string ref
std::string* dir3 = el.get_ptr<std::string*>(); // access string ptr
const char* dir4 = el.get_ptr<std::string*>()->c_str();
} I haven't tested the code. but you should get the idea. Docs: |
@kenshen112 Do you need further assistance? |
The purposed solution worked |
"Item" : ["data", "data"]
charArray = ["Array"].get<char*>();
What is the expected behavior?
It reads the array from the file into the char pointer array
And what is the actual behavior instead?
Error C2338 incompatible pointer type
Which compiler and operating system are you using? Is it a [supported compiler]
Visual Studio 2017
Did you use a released version of the library or the version from the
develop
branch? NoThe text was updated successfully, but these errors were encountered: