|
From: Fernando L. <fer...@gm...> - 2007-07-09 05:26:52
|
Yohaan,
Function strcmp applies to null terminated char arrays, strings are a C++
data type.
Replace
if (strcmp (noble,helium.aname)=3D=3D0) {
with
if (noble.compare (helium.aname)=3D=3D0) {
Best regards,
Fernando
On 7/8/07, J Hall <jsh...@ho...> wrote:
>
> i cant figure out how to use the strcmp to compare the string noble to
> the object helium with the member string name...??!!
>
> this is the error that is stopping the compiler...
>
> 44 C:\Dev-Cpp\Untitled1.cpp no matching function for call to
> `strcmp(std::string&, std::string&)'
>
> #include <stdio.h>
> #include <iostream>
> #include <string.h>
> #include <cstring>
>
> using namespace std;
> struct elements{
> string aname;
> int atomic_no;
> float atomic_weight;
> }helium, neon, argon, krypton, xenon, radon;
>
> int x;
> main()
> {helium.aname =3D "helium";
> helium.atomic_no =3D 2;
> helium.atomic_weight =3D 4;
> neon.aname =3D "neon";
> neon.atomic_no =3D 10;
> neon.atomic_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;
> xenon.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 Begining of the Periodic Table of the Elements \n");
> printf ("\t In the hopes of learning C programming and elemental values.
> \n\n\n");
>
> cout << "\t Please enter 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 appreciated
>
> thanks
> yohaan
>
> ------------------------------
> See what you're getting into=85before you go there. Check it out!<http://=
newlivehotmail.com>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
--=20
Fernando Lichtschein
li...@fi...
|