-
At startup, the program crashes, I assume that the problem is in the convert method (if you do as in the first argument, the conversion first into a string and then into characters, then everything is OK) How can this be corrected? Code below (Yes, the setValue method takes const char*) /// |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
This has nothing to do with the library. Your convert function is returning a pointer from a temporary std::string (it's passed by value instead of reference), so it's invalid as soon as the function returns. |
Beta Was this translation helpful? Give feedback.
That's because
dataResult["id"]
isn't astd::string
, it's ajson
. You need to convert it to astd::string
as you did with_id
.or to be safer if you don't know for sure that there is an
"id"
child indataResult
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 toini.SetValue()
. This applies to bothconst char *
parameters toini.SetValue()
, asdefId
dies when_id
is destroyed.