image
Physics Forums Logo
image
image
* Register * Upgrade Blogs Library Staff Rules Mark Forums Read
image
image   image
image

image Small and quick C++ problem Share It Thread Tools Search this Thread image
Old Oct4-05, 05:57 PM                  #1
Zurtex

Zurtex is Offline:
Posts: 1,121
Recognitions:
Homework Helper Homework Helper
Science Advisor Science Advisor
Small and quick C++ problem

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.
  Reply With Quote
Old Oct4-05, 06:02 PM                  #2
neurocomp2003

neurocomp2003 is Offline:
Posts: 1,372
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)
  Reply With Quote
Old Oct4-05, 06:05 PM                  #3
samh

samh is Offline:
Posts: 43
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
  Reply With Quote
Old Oct4-05, 06:05 PM                  #4
Zurtex

Zurtex is Offline:
Posts: 1,121
Recognitions:
Homework Helper Homework Helper
Science Advisor Science Advisor
Originally Posted by neurocomp2003
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
  Reply With Quote
image image
Reply
Thread Tools


Similar Threads for: Small and quick C++ problem
Thread Thread Starter Forum Replies Last Post
Quick Optics Question on Gratings (Small calculation) _Mayday_ Classical Physics 5 Jan21-08 01:37 PM
Small electric generator, driven by a small engine shaft idarab Mechanical Engineering 11 Apr16-07 03:45 PM
A small problem Rahmuss Brain Teasers 9 May19-05 04:44 PM
small problem john425 Calculus & Analysis 4 Oct30-04 05:24 PM
Small problem, can anyone help? Vlad General Math 1 May6-04 09:46 PM

Powered by vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd. © 2009 Physics Forums
Sciam | physorgPhysorg.com Science News Partner
image
image   image