I am trying to prepare json request using c++. Like this:
string key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
std::string data = "{\n"
" \"foo\": key\n"
"}";
When I print this, it's shows like :
"foo": key
But I need like this :
"foo": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
So, please someone help me. How to do this? Thanks in advance.
C++ doesn't expand variables inside a string constant, so if you have "key" inside such a string, it'll just be interpreted as the string "key" rather than expanded as a variable.
What you want to do is concatenate the contents of the variable "key" with the rest of your string. In C++, you can just do this with the concatenation operator "+".
So you'll want something like:
std::string data = "{\n"
" \"foo\": " + key + "\n"
"}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With