I am using c++11
. When I use the +=
operator for concating strings or characters, it does not work, however =
, works.
e.g. I used all the below test cases independently, i.e. separately.
string s="abdddddd";
string ss="";
ss+=s[0];//working
ss+=s[0]+s[1]; //not working output: Ã
ss+="hi"+s[2]; //not working no output
ss+='d'+'c'; //not working output: З
ss+="hi"+"string"; //not working error: invalid operands of types ‘const char [3]’ and ‘const char [7]’ to binary ‘operator+’
string another="this";
ss+=another+'b'; //working
ss+="hi"+another;//working
ss+=("hi"+s[3]); //not working
ss=ss+"hi"+s[3]; //working
ss=ss+"hi"+"this"; //working
Also adding brackets doesn't work. So, I want to know why it doesn't work with strings, it works with adding integers.
Aucun commentaire:
Enregistrer un commentaire