Anwar Mohamed
Anwar Mohamed

Reputation: 653

C++ concat const char with char

i have defined a value using

extern char WEBSRV_ADMIN_ID[31];    char WEBSRV_ADMIN_ID[31]=   "admin";

then i want to use the username in a char statement into sql as

const char *pSQL[1];
pSQL[1] = "update websrv_config set admin_id='" + WEBSRV_ADMIN_ID + "'";

but it seems that there is an error

error: invalid operands of types ‘const char [36]’ and ‘char [31]’ to binary ‘operator+’

how can i overcome it?

Upvotes: 1

Views: 920

Answers (1)

Kos
Kos

Reputation: 72261

in C++, use std::string. It handles + will work as you want it to.

In C, allocate a buffer big enough to contain the whole query and fill it part-by-part using strncat.

Upvotes: 7

Related Questions