472,958 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

invalid operands const char* to binary 'operator+'

SwissProgrammer
220 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;

2 6281
dev7060
626 Expert 512MB
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
220 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

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

Similar topics

4
by: muthu | last post by:
In the following code it gives the error "error: invalid operands to binary &" Why it is happening #include <signal.h> #include <errno.h> #define SIGBAD(signo) ((signo) <= 0 || (signo) >=...
1
by: Richard Eich | last post by:
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3) source snippet: .... int i = 17 ; if ( 0x03 & i ) ....
11
by: Spiros Bousbouras | last post by:
#include <stdlib.h> int main(void) { char **p1 ; const char **p2 ; p1 = malloc(5 * sizeof(char *)) ; if (p1 == 0) return EXIT_FAILURE ; p2 = p1 + 1 ; p2 - p1 ;
2
by: xelloss | last post by:
#include<cstdlib> #include<iostream> #include<iomanip> #include<vector> #include<fstream> using namespace std; double sum(vector<double> x) { double total = 0.0;
13
by: S S | last post by:
Hi I have a very basic question, but it's a good one. Below is the code fragment. struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0;
7
by: Bill Davy | last post by:
I want to be able to write (const char*)v where v is an item of type Class::ToolTypeT where ToolTypeT is an enumeration and I've tried everything that looks sensible. There's an ugly solution, but...
2
by: Tyler Palmer | last post by:
I am having a problem with my program. I cant figure out a solution for the compiler error im getting. In function `double endingConversion(double)': invalid operands of types `double...
15
by: categami | last post by:
hey i need help with this this error keeps popping up on line 20 invalid operands of types `int' and `int ()(int)' to binary `operator-' is there any help i can get please help me!!! thank you...
2
by: SunDevil1171 | last post by:
I making a simple single number scrambler/encryptor and as I tried to build the console application the following error occurred: error: invalid operands of types 'void' and 'int' to binary...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.