the compiler return me the error "invalid operands of types 'char*' and 'const char [2]' to binary 'operator+'" when trying to do this simple code:
BodyText[client] = PS3::ReadString(0x0178646c) + "\n" ;
Here my ReadString() function:
char returnRead[100];
char* ReadString(int address)
{
memset(&returnRead[0], 0, sizeof(returnRead));
int strlength = 100;
char* StrBytes = ReadBytes(address, strlength);
for (int i = 0; i < strlength; i++)
{
if (StrBytes[i] != 0x00)
returnRead[i] = StrBytes[i];
else
break;
}
return returnRead;
}
Thanks anyway for reading
Best Solution
This is because there is no
operator+
forchar*
(the return-type of your function) andconst char[2]
(the type of"\n"
), and since you cannot overload operators for built-in types, there cannot be one. Since this question is tagged C++:Just use
std::string
instead ofchar*
, all your problems are solved already.std::string
will be superior to the hacks you try to do.Here you can find a overview over
strings
features and examples how to use them. You then can concatenate stringsa,b,c
likestd::string new_string = a + b + c;