I can't understand the meaning of function
size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
I was trying to run simple curl function on c++, for usage inside ue4. Curl works fine, but i am trying to read response, receive response into string, as it works kinda js ajax.
Found the solution from here
In xcode c++ works fine
But in ue4 :
using std::string
((std::string*)userp)->append((char*)contents, size * nmemb);
/Users/Documents/Unreal Projects/curlTest/Source/curlTest/curlTestCharacter.cpp:114:7: error: no member named 'string' in namespace 'std'; did you mean 'cString'?
Using cString :
((cString*)userp)->append((char*)contents, size * nmemb);
/Users/Documents/Unreal Projects/curlTest/Source/curlTest/curlTestCharacter.cpp:114:15: error: expected expression
Trying to find out the reason, but don't know the function above, how it works, if xcode runs fine so then, for what reason is it so. Anonymous function , pointer and some features of c++?
How can i use this code more human, or more easily, and how to deal with errors?
No math, no addition - subtraction, var or func, class or object, what is the meaning if this code
((std::string*)userp)->append((char*)contents, size * nmemb);
And as i still didn't found how to receive curl response as easy as ajax does, this still may work, but how does it works and how can i use it?
Any help, two days trying to figure out, trying to simply run the curl which i previously used so easy in command line and php code
size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
Without any further context, I would guess that this is some callback a library (curl maybe?) is calling to let you process received data. contents
is the string data itself, size
and nmemb
describe how much data is in the string (size
is the width of each character and nmemb
is the count of characters, perhaps?), userp
is a custom data pointer you probably pass in when you call the function that generates calls to this callback. I'm guessing that you're meant to return the number of bytes you processed.
In the case of this particular function, I'm guessing you're passing in a std::string
pointer. Whenever this library has received data, it's appending it into your std::string
.
((std::string*)userp)->append((char*)contents, size * nmemb);
/Users/Documents/Unreal Projects/curlTest/Source/curlTest/curlTestCharacter.cpp:114:7: error: no member named 'string' in namespace 'std'; did you mean 'cString'?
This is caused by not including the header - add #include <string>
at the top of your source file.
((cString*)userp)->append((char*)contents, size * nmemb);
/Users/Documents/Unreal Projects/curlTest/Source/curlTest/curlTestCharacter.cpp:114:15: error: expected expression
It would appear that the cString
class does not have a member function called append
. You'll have to either look at the cString
's header file or consult its documentation to work out what the appropriate function to use is.