I have a script that is using the internet protocol 'Curl'

I am sending a http _POST to a php file. To send a post with curl, I need to make a char variable with all my info. for example "name=andrew&country=usa"

Here is where the problem comes in - One of the pieces of info I have to post is created AFTER the program starts. it's a unique id that the program uses to register itself to the servers. That means that I have to do something like this:

char *uniqueid = whatever the program has created

char *post = "request=register&uniqueid=" + uniqueid;

**curl info here**

But here is the error i get:

483 E:\script\main.cpp invalid operands of types `const char[75]' and `char*' to binary `operator+'

I'm not sure how to bypass this. all I need to do is stick 2 different char variables together. Thanks! :)

Edited by mybluehair: n/a

7 Years
Discussion Span
Last Post by Ancient Dragon

Not sure what C++ library are you using. It looks like you are trying to concatenate a string with char while the library does not include + operator overload... You need to use string concatenation, but I do not know your library syntax. Someone else should know this.

Edited by Taywin: n/a


>>char *post = "request=register&uniqueid=" + uniqueid;
You can not concantinate C style character arrays that way. It has nothing to do with libcurl -- just plain old C syntax error

char post[255];

Of course you could use std::string to make it a little easier, and safer

std::string uniqueid = "whatever";
std::string post = "request=register&uniqueid=";
post += uniqueid;

In the libcurl function parameters which require const char* you can use post.c_str().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.