R
Robbie Hatley
Say I have an ifstream object, like so:
#include <iostream>
#include <fstream>
int main(int, char* Sam[])
{
std::ifstream Bob;
Bob.open(Sam[1]);
std::string buffer;
while (42)
{
getline(Bob, buffer);
if (Bob.fail()) std::cerr << "Stream failed!" << std::endl;
if (Bob.eof())
{
std::cout << "eof" << std::endl;
break;
}
std::cout << buffer << std::endl;
}
return 0;
}
On my compiler, fail() will come up true whenever eof
occurs. And yet, I've read that fail() is supposed to
to be true only when a non-eof stream failure occurs:
http://www.cplusplus.com/ref/iostream/ios/fail.html
So, is my compiler messing up? Or is the info on that
web site wrong? They can't both be right.
--
Puzzled,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
#include <iostream>
#include <fstream>
int main(int, char* Sam[])
{
std::ifstream Bob;
Bob.open(Sam[1]);
std::string buffer;
while (42)
{
getline(Bob, buffer);
if (Bob.fail()) std::cerr << "Stream failed!" << std::endl;
if (Bob.eof())
{
std::cout << "eof" << std::endl;
break;
}
std::cout << buffer << std::endl;
}
return 0;
}
On my compiler, fail() will come up true whenever eof
occurs. And yet, I've read that fail() is supposed to
to be true only when a non-eof stream failure occurs:
http://www.cplusplus.com/ref/iostream/ios/fail.html
So, is my compiler messing up? Or is the info on that
web site wrong? They can't both be right.
--
Puzzled,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/