467,166 Members | 1,044 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

invalid operands const char* to binary 'operator+'

SwissProgrammer
128KB
A question from help I was getting on page https://bytes.com/topic/c/answers/974514-what-minimum-requirements-all-17-planes-unicode-c#post3829190



There is a lot on that page, so I separated this into a new question.


Previous:
Expand|Select|Wrap|Line Numbers
  1.     string tempString = "";
  2.     string stringByte;
  3.     string words;
  4.  
  5.     for (char& _char : words) {
  6.         numToString = to_string (i);;
  7.         stringByte = bitset<8>(_char).to_string();
  8. // etc.    
  9.  
I get the following error if I do not split up the next two lines

error: invalid operands of types 'const char*' and 'const char [23]' to binary 'operator+'

With error:
Expand|Select|Wrap|Line Numbers
  1. tempString = "\n      [" + _char + "]=<Combined_1 PLANE 0>" + stringByte;

Without error:
Expand|Select|Wrap|Line Numbers
  1.                         tempString = "\n      [" + _char;
  2.                         tempString = tempString  + "]=<Combined_1 PLANE 0>" + stringByte;
  3.  

I have been trying to understand this.
What is it saying that I need to do?


Help please.

Thank you.
Dec 12 '20 #1

✓ answered by dev7060

error: invalid operands of types 'const char*' and 'const char [23]' to binary 'operator+'
The overloaded operator+ expects at least one operand to be of string type. Try this:
Expand|Select|Wrap|Line Numbers
  1. tempString = string("\n      [") + _char + string("]=<Combined_1 PLANE 0>") + stringByte;

  • viewed: 2028
Share:
2 Replies
Expert 256MB
error: invalid operands of types 'const char*' and 'const char [23]' to binary 'operator+'
The overloaded operator+ expects at least one operand to be of string type. Try this:
Expand|Select|Wrap|Line Numbers
  1. tempString = string("\n      [") + _char + string("]=<Combined_1 PLANE 0>") + stringByte;
Dec 15 '20 #2
SwissProgrammer
128KB
dev7060,

Thank you.

You said, "at least one operand" therefore I have been studying how to do this with the other parts:
_char
I found Microsoft documentation at https://www.techiedelight.com/conver...to-string-cpp/
and
stringByte
is already a string, but not quite acceptable because it filled it with
Expand|Select|Wrap|Line Numbers
  1. stringByte = bitset<8>(_char).to_string();
which was not accepted by the compiler as a string.
I guess that I have to re-make it a string.
(I expect that "re-make it" is not the correct wording, but I am not certain how to say that.)

Using your guidance, I have studied this (some) and now can use this:
Expand|Select|Wrap|Line Numbers
  1.                 string a1 = "\n      [";
  2.                 string a2(1, _char);
  3.                 string a3 = "]=<Combined_1 PLANE 0>";
  4.                 string a4 = stringByte;
  5.  
  6. //                tempString = string("\n      [") + _char + string("]=<Combined_1 PLANE 0>") + stringByte;
  7.                 tempString = a1 + a2 + a3 + a4;/


Thank you.
Dec 16 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by muthu | last post: by
1 post views Thread by Richard Eich | last post: by
11 posts views Thread by Spiros Bousbouras | last post: by
13 posts views Thread by S S | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.