Learning c++ using Codelite.
This works:
string z
z="";
z=z+"123"+"4";
but this will not compile: (invalid operands...binary operator)
z= "123" + "4" ;
I found from trial and error I had to start any concatenation assignment with a string variable, otherwise it won't compile.
Can someone help me understand why?
noob string question
-
- CodeLite Curious
- Posts: 4
- Joined: Sat Aug 09, 2014 2:22 am
- Genuine User: Yes
- IDE Question: C++
- Contact:
noob string question
Old programmer, noob at Codelite and C++, please have mercy and tailor replies accordingly
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: noob string question
This is because std::string has an operator + overloaded, but not char*
So writing: will return a reference to std::string ( and this why you can add another const char* )
While: is undefined
But these kind of questions should really be posted on stackoverflow.com or any c++ forum, but not here
Eran
So writing:
Code: Select all
std::string + const char*
While:
Code: Select all
const char* + const char*
But these kind of questions should really be posted on stackoverflow.com or any c++ forum, but not here
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 4
- Joined: Sat Aug 09, 2014 2:22 am
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: noob string question
Thank you, Appreciate the pointer to c++ help.But these kind of questions should really be posted on stackoverflow.com or any c++ forum, but not here
Old programmer, noob at Codelite and C++, please have mercy and tailor replies accordingly