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! :)

Recommended Answers

All 2 Replies

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.

>>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];
strcpy(post,"request=register&uniqueid=");
strcat(post,uniqueid);

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().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.