|
From: Per W. <pw...@ia...> - 2007-07-09 01:24:40
|
You are mixing C and C++. strcmp() is used for zero-terminated C strings.
When using the std::string data type, you can directly compare the strings
just as if they where integers, i.e. by using operators < <=3D =3D=3D >=3D =
>.
/pwm
On Sun, 8 Jul 2007, J Hall wrote:
>
> i cant figure out how to use the strcmp to compare the string noble to t=
he object helium with the member string name...??!!this is the error that i=
s stopping the compiler...44 C:\Dev-Cpp\Untitled1.cpp no matching function =
for call to `strcmp(std::string&, std::string&)' #include <stdio.h>#includ=
e <iostream>#include <string.h>#include <cstring>using namespace std;struct=
elements{ string aname; int atomic_no; float atomic_weig=
ht; }helium, neon, argon, krypton, xenon, radon; int x;main(){hel=
ium.aname =3D "helium"; helium.atomic_no =3D 2; helium.atomic_wei=
ght =3D 4; neon.aname =3D "neon"; neon.atomic_no =3D 10; neon.a=
tomic_weight =3D 20.1797; argon.aname =3D "argon"; argon.atomic_no =
=3D 18; argon.atomic_weight =3D 39.948; krypton.aname =3D "krypton"=
; krypton.atomic_no =3D 36; krypton.atomic_weight =3D 83.80; xe=
non.aname =3D "xenon"; xenon.atomic_no =3D 54; xenon.atomic_weight=
=3D 131.29; radon.aname =3D "radon"; radon.atomic_no =3D 86; =
radon.atomic_weight =3D 222.0176; string noble; string title("\n\t You =
have selected :\t"); string no("\n\t The atomic number for "); string is(" =
is:\t"); string wgt("\n\t The atomic weight is:\t");printf ("\t The Beginin=
g of the Periodic Table of the Elements \n");printf ("\t In the hopes of le=
arning C programming and elemental values. \n\n\n");cout << "\t Please ente=
r a Noble Gas you would like to examine." ;cin >> noble; if (strcmp (noble,=
helium.aname)=3D=3D0) { cout << title << helium.aname; =
cout << no << helium.aname << is << helium.atomic_no; cout << =
wgt << helium.atomic_weight;}; cin >> x; }this is what i have got=
so far... any help would be appreciatedthanks yohaan
> _________________________________________________________________
> See what you=92re getting into=85before you go there.
> http://newlivehotmail.com
|