[Tutor] Can any one recommend a good C++ referernce manual

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri Nov 15 16:36:02 2002


[off topic C++ post; ignore to avoid confusion with Python]


On Fri, 15 Nov 2002 alan.gauld@bt.com wrote:

> In that case it didn't teach you enough! The differences at a conceptual
> level are not grweat but to effectively use C++ the differences are
> vast.

It's weird, but I really have seen some C++ tutorials that try to pretend
that files don't exist.  *grin*

C++'s file handling libraries are meant to mimic the character streams,
so, technically, there should't be anything new to learn.



> > doesn't give many functions, I cant even seem to find how to write to
> > a file.
>
> The functions are, like in python, contained in libraries. You need
> documentation for the standard C++ library. For file handling look at
> the streams library(obviously! :-) or use the old C stdio library.



There's an fairly good C++ reference out there from Dinkumware:

    http://www.dinkumware.com/refxcpp.html


What we want to use for file input and output is probably the 'fstream'
library, which provides 'file streams' that are similar to the 'cin' and
'cout' objects that we're accustomed to in C++.


For example, here is a C++ program that uses a output file stream to write
something out:

//////
#include <fstream>

void main() {
  ofstream out("test_fstream.txt");
  out << "Hello world!\n";
  out.close();
}
///////



And just to make sure this post is somewhat relevant to Python, here's
equivalent Python code for comparison's sake:

###
if __name__ == '__main__':
    out = open("test_fstream.txt", "w")
    out.write("Hello world!\n")
    out.close()
###


So, even in C++, simple file input and output is very possible.



If you're going to do C++ seriously, you really should feel comfortable
with the stream libraries.  The 'strstream' library is especially
important, since it's one of the main ways of converting between strings
and other C++ values.

You should probably ask more questions on a C++ specific newsgroup or
mailing list.  The 'comp.lang.c++' newsgroup is a good one that should
help fill the gaps in your book knowledge.  There's also a lot of good
knowledge in the C++ faqs:

    http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c++.html



I hope this helps.  Good luck!