TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARIN MCBRIDE
from: ROGER SCUDDER
date: 1998-02-09 16:47:00
subject: C++ Saveding stuff

Hello Darin.
07 Feb 98 12:00, Darin McBride wrote to Roger Scudder:
RS>>> TM>     if (name=="Cyber Con")
RS>>>  That doesn't work.  You're comparing addresses.  Use strcmp.
TM>> No. I call an overloaded operator==().
RS>>  And you expect a complete novice to understand that without
RS>>  even a comment?   I assumed that this would be your response,
RS>>  but I think you should provide the code for the overloaded
RS>>  operator if you are going to present such an advanced OO
RS>>  technique to a novice.
DM> Not really - this is standard C++ style.  And one of the things that make 
DM> it difficult for C programmers to make the switch to C++.  Yes, teaching 
DM> someone C++ should tell them what is going on in the background, but if I 
DM> was to post working code as a snippet, it shouldn't need that as long as 
DM> name was declared "string name" rather than "char* name".
 Well, I still would have liked to see a little explanation as
 to what was going on.   If I see something that doesn't look
 right to me, I just going to blast about it.  It worked great
 this time.  It occurs to me that trying to tell someone they
 are wrong when they are right is great way to get lots of
 information on the subject.
 Here's something I'm not clear about...
#include 
int main( void )
{
    ifstream source ("infile");
    if(!source)
        blablabla...
 When is the file opened in that snip?  Is the reason this works
 the same as why the next line works?
RS>>> TM>     ofstream("file1.fil") << name;
 Because the filename is hard coded?   In other examples I have been
 looking at where the filename must be supplyed by the user at runtime
 the files are opened using this syntax...
  ifstream infile;
  
  infile.open( argv[1]. ios::in )
 Can you give me a few words about how this works?
DM> It is done explicitly - by the ofstream's destructor.  That's the power 
of 
DM> classes - they automatically allocate/deallocate things for you.  The 
 It sounds very good indeed!
DM> Trust me - when you start putting reference-counting objects that point 
to 
DM> hierarchies of class types into containers, you will have a hard time 
DM> knowing when to close that file - let the destructor do it for you.  You 
DM> will get cleaner code, and be less likely to have a memory/resource leak. 
 
DM> Been there, done that.
 OK.  I trust you.... well, as far as coding is concerned. ;-)
 Actually that makes a lot of sense to me and helps to tie together
 some of the reading I have been doing.
RS>>  Here's the errors I get when I try to compile your code.
DM> Note that "string" is standard, but not implemented standardly 
everywhere.  
DM> That is most likely your problem.  Try a "more up to date" compiler 
(gcc?).
 Well, I tried it with BC++ 3.1 and it's looking more and more
 like a C compiler all the time.   I'll stick to MSVC 5 from now
 on.  That way if I work in the Visual Studio I'll have all the
 references right there.  In fact I'm going to take some time to
 read through the docs about the string and io classes.
 -Roger
... I am Magnus Magnuson of Borg. Your score is irrelevant.
--- Msged 4.20 beta 3
(1:273/404@fidonet)
---------------
* Origin: Hodge-Podge Support BBS, Upper Darby, Pennsylvania, USA

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.