ian reinhart geiser on Wed, 19 Jun 2002 22:10:30 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] this code crashes [OT]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 19 June 2002 09:55 pm, Fred K Ollinger wrote:
> > Whoa!
> > you are MIXing C and C++... Bad move
> > fstream is what you really want to be using./
>
Well great, but I still need to write to this file.
>
ifstream in("sourcefile");
ofstream out("destfile");
string s = "";
while (getline(in,s))
	out << s << "\n";

This will do text just fine.  For a binary file you can do things like 
getch().  C++ is  a more modern approach so unless you are good at C or need 
to fit this applicaiton into 64K or less things like C++, python and even 
perl are FAR more suitable for the situation.  Check out Bruce Eckel 
"Thinknig in C++" its in PDF form on the web and is a very good book for C 
programmers needing to get up to speed.

> 
> I'm going to start looking over this class as well. I guess blew my
> chances of ever being hired as a c++ coder for anyone in plug. Shh. I got
> this job on the basis of other code that I made so I don't feel that I
> misrepresented or anything. :)
>

heh, np, i know enough C to debug it, and i am no C guru.  Its just the last C 
i really touched was on a 8bit 68HC11 micro controller.  

> I checked and double checked the code I have. I don't see a bug that would
> segfault, though I mentally predicted that messy loop problem (and tried
> to fix it), a problem, but not enough to segfault.

The reason C++ came about was to release developers from the harsh evils of C 
when it came to doing anything beyond basic array manipulation.  Like 
assembly many neat things can be done in C, and some times they are very 
quick and small.  But you have to ask your self, "Is 25 lines of C that run 
really really fast and took me 12 hours to write, worth all of that 5 minutes 
that it took me to write this in python?"  Granted that is an exageration but 
you get the point I am trying to make :)

If you have any problems do a google search on ifstream (for input hence the 
name) and ofstream for output.  they have very similar operators to istream 
and ostream, since they i think are both derived from ios.  I could be wrong 
since it has been 6 years since I had that class :)

Cheers
- -ian reinhart geiser
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9ETmLPy62TRm8dvgRAiXqAJ4zSS0M9iUlLpWHSfZ7QoAj5Z/cLACg4bb9
cIHSoMt4OKlXjCDHOQMjVw4=
=J5YK
-----END PGP SIGNATURE-----


______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug