Troubleshooting C++ Program: Invalid Conversion Error

  • Thread starter Thread starter Zurtex
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
The discussion centers on a C++ programming error related to character assignment. The user encounters an "invalid conversion from `const char*` to `char`" when trying to assign a string literal "=" to a character variable. It is clarified that single quotes ('=') should be used for a single character, while double quotes ("=") denote a string. The distinction between character pointers and character types is emphasized, with the correct syntax being crucial for successful compilation. Understanding this difference resolves the user's issue with the program.
Zurtex
Science Advisor
Homework Helper
Messages
1,118
Reaction score
1
Just been introduced to the world of C++ as I'm taking a course on it in my maths degree. We are asked to write a simple program that takes in 3 numbers, sorts them in terms of order and then outputs them.

Not going to type my full program as that would probably be a waste of your time but here are the two important lines I am stuck on:

char qualifier1;
...
qualifier1 = "=";

And I'm getting the error when I try to compile this:

invalid conversion from `const char*' to `char'

Can anyone help me please, I'm not sure what this means and I am struggling to fix it.
 
Physics news on Phys.org
i believe the correct syntax for a single char is ' ' not " "...if i remember correctly " " denotes strings...and thus your error is saying
cannot convert const char* "=" (string) to a char (single char qualifier)
 
Using double quotes ("") in C and C++ returns a constant character pointer which points to a null-terminated string in the static section of memory. So if you write char* ptr = "dog"; you get ptr pointing to a character array consisting of 'd', 'o', 'g', and '\0', the null terminator.

What you're looking to do is use single quotes. When you type "=", you get the C-string "=". What you want to do is '=', with single quotes. This returns a plain character.

Edit: whoops too late
 
neurocomp2003 said:
i believe the correct syntax for a single char is ' ' not " "...if i remember correctly " " denotes strings...and thus your error is saying
cannot convert const char* "=" (string) to a char (single char qualifier)
Thanks :biggrin:
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'Minimum mass of a block'
Here we know that if block B is going to move up or just be at the verge of moving up ##Mg \sin \theta ## will act downwards and maximum static friction will act downwards ## \mu Mg \cos \theta ## Now what im confused by is how will we know " how quickly" block B reaches its maximum static friction value without any numbers, the suggested solution says that when block A is at its maximum extension, then block B will start to move up but with a certain set of values couldn't block A reach...
Thread 'Calculation of Tensile Forces in Piston-Type Water-Lifting Devices at Elevated Locations'
Figure 1 Overall Structure Diagram Figure 2: Top view of the piston when it is cylindrical A circular opening is created at a height of 5 meters above the water surface. Inside this opening is a sleeve-type piston with a cross-sectional area of 1 square meter. The piston is pulled to the right at a constant speed. The pulling force is(Figure 2): F = ρshg = 1000 × 1 × 5 × 10 = 50,000 N. Figure 3: Modifying the structure to incorporate a fixed internal piston When I modify the piston...

Similar threads

Replies
2
Views
2K
Replies
7
Views
2K
Replies
23
Views
2K
Replies
14
Views
5K
Replies
7
Views
3K
Replies
14
Views
34K
Back
Top