RE: [Dev-C++] Operator overloading for built in types.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Damien A <g_...@ho...> - 2003-12-27 16:48:07
|
<html><div style='background-color:'><DIV class=RTE>
<P><BR></P>
<P>You could change your code to use C++ strings instead of char*. That way, you
<DIV>wouldn't have to write your own == function, as it is one of the methods of the C++ string class. </DIV>
<DIV> </DIV>
<DIV>#include <iostream><BR>#include <string><BR>using namespace std;<BR>int main()<BR>{ <BR> string x = "Hello";<BR> string y = "Hello";<BR> if(x == y)<BR> cout << "Equal" << endl;<BR> else<BR> cout << "Not equal" << endl;<BR> cin.get();<BR> return 0;<BR>}</DIV>
<P></P>
<P><BR></P></DIV>
<DIV></DIV>>From: David McKen <CI...@YA...>
<DIV></DIV>>Reply-To: ci...@ya...
<DIV></DIV>>To: Dev-C Mailing List <DEV...@LI...>
<DIV></DIV>>Subject: [Dev-C++] Operator overloading for built in types.
<DIV></DIV>>Date: Sat, 27 Dec 2003 06:37:31 -0800 (PST)
<DIV></DIV><mailto:dev...@li...?subject=unsubscribe><mailto:dev...@li...><mailto:dev...@li...?subject=help><mailto:dev...@li...?subject=subscribe>
<DIV></DIV>>
<DIV></DIV>>Ok here is my dilema.
<DIV></DIV>>
<DIV></DIV>>Scattered throught my code is the following line:
<DIV></DIV>>
<DIV></DIV>>if(!strcmp(var1,var2))
<DIV></DIV>>....
<DIV></DIV>>
<DIV></DIV>>What would be the best way to change that to
<DIV></DIV>>
<DIV></DIV>>if( var1 == var2 )
<DIV></DIV>>....
<DIV></DIV>
<P>
<DIV> </DIV></P></mailto:dev...@li...?subject=subscribe></mailto:dev...@li...?subject=help></mailto:dev...@li...></mailto:dev...@li...?subject=unsubscribe></div><br clear=all><hr>Add photos to your messages with <a href="http://g.msn.com/8HMAEN/2749??PS=">MSN 8. </a> Get 2 months FREE*.</html>
|