Greg wrote:
[color=blue]
> Please forgive my ignorance, but I'm still struggling with many aspects
> of ANSI/ISO Standard C++ .[/color]
[color=blue]
> I have several questions: (1) I have a
> "using namespace std" statement below my preprocessor directives ( #
> include <...>). Does that mean I don't have to use the "std::" prefix?[/color]
Basically, yes. It brings all the symbols that are contained
in std:: to the global namespace. Make sure, however, that you
don't use 'using namespace std' in header files, only in
source files.
[color=blue]
> (2) What's the difference between "std::getline( )" and, in my
> particular case: "InputFile.getline( )" ?[/color]
The first gets the line into a std::string, the latter into
a char[] array. Therefore the first one doesn't rely on the
line being 'short enough' to fit your fixed-size char[] array.
std::string can grow to accomodate data.
[color=blue]
> (4) Is using the ".eof ( )"
> function not as straightforward as it appears?[/color]
It is not.
[color=blue]
> Isn't it a boolean
> function that takes no input parameters? In my particular case, I'm
> using "InputFile.eof( )"[/color]
Yes it is.
The trouble with .eof() is that you can't reliably tell
if a stream is at EOF *before* you try to read the last
datum. For instance someone can append data to the stream in
the meantime, or if the stream is tied to the keyboard it's
hard to tell EOF at all. For a longer explanation try
http://www.parashift.com/c++-faq-lit....html#faq-15.5
Perhaps you could catch the exception and see what it is?
#include<exception>
try {
// getline stuff
}
catch(exception &e) {
cerr "Shit has just happened: " << e.what() << endl;
}
HTH,
- J.