3 ms·
> "Using the "+" operator with two string constants gives a weird compiler error about adding pointers?" He'd have that in C too, and that's the expected behav
by klingonopera 7y ago
> "Using the "+" operator with two string constants gives a weird compiler error about adding pointers?"
He'd have that in C too, and that's the expected behaviour. What he would want is:
#define STRING1 "hello"
#define STRING2 "world"
const char* gString = STRING1 " " STRING2 "!\n";
#include <stdio.h>
int main() {printf(gString); return 0x0;}
- AstralStorm 7y agoIf you make them string constants rather than character arrays with the new literal ""s added in C++14, problem is gone. Author is using outdated C++. This is all due to C compatibility.
- klingonopera 7y agoAh, yeah... no clue about C++'s strings, I just read his question and that sounded familiar to the problem, whose solution I posted above. There's some overlap between C and C++, but maybe this wasn't such a case? Sorry, if it was uncalled for.