1
char stringToAdd[4097] = ""; 

// some manipulations on stringToAdd to add some value to it. 

if(stringToAdd[0] != '\0') { 
response = MethodCalledHere("Some Random text");
}

MethodCalledHere(const String& inputParameter) {
 // some method definition here.
}

I've to add stringToAdd to the "Some Random text". Something like -

response = MethodCalledHere("Some Random text" + stringToAdd);

But this gives me error that '+' cannot add two pointers.

Any suggestions?

user2769790
  • 123
  • 1
  • 17

2 Answers2

2

But this gives me error that '+' cannot add two pointers.

That's because in that context, both sides of the + operator are pointers.

Use

response = MethodCalledHere(std::string("Some Random text") + stringToAdd);

If your function expects char const*, then, you can construct a std::string first and then use std:string::c_str().

std::string s = std::string("Some Random text") + stringToAdd;
response = MethodCalledHere(s.c_str());

If you are able to use C++14, you can use the string literal (Thanks are due to @Bathsheba for the suggestion).

response = MethodCalledHere("Some Random text"s + stringToAdd);
R Sahu
  • 204,454
  • 14
  • 159
  • 270
0
auto MethodCalledHere(std::string inputParameter) {
    inputParameter.append(stringToAdd, 
                          stringToAdd + std::strlen(stringToAdd));
    return inputParameter;
}
Richard Hodges
  • 68,278
  • 7
  • 90
  • 142