Skip to content

Conversion to const char* #4136

Closed Answered by gregmarr
Kolhun asked this question in Q&A
Sep 6, 2023 · 1 comments · 8 replies
Discussion options

You must be logged in to vote

That's because dataResult["id"] isn't a std::string, it's a json. You need to convert it to a std::string as you did with _id.

dataResult["id"].get<std::string>().c_str()

or to be safer if you don't know for sure that there is an "id" child in dataResult

dataResult.value<std::string>("id", "some default value").c_str()

Note that this is STILL a temporary, and it will be destroyed as soon as the statement finishes, so ini.SetValue needs to copy the string, but at least now it survives the call to ini.SetValue(). This applies to both const char * parameters to ini.SetValue(), as defId dies when _id is destroyed.

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@Kolhun
Comment options

@gregmarr
Comment options

@Kolhun
Comment options

@gregmarr
Comment options

Answer selected by Kolhun
@Kolhun
Comment options

@gregmarr
Comment options

@Kolhun
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants