469,928 Members | 1,814 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

ifstream::is_open() not found on Solaris C++ compiler

Hi,
We are working on Solaris SunOS 5.8. We are using ifstream of iostream
namespace. The snippet is given below:

#include <iostream.h>
#include <fstream.h>

boolean readFile()
{
char readStr[256];

ifstream infile;
infile.open("123768_20010706_2001.csv");

if (infile.is_open())
{
while (infile.good())
{
infile.getline(readStr,256,'\n');
cout << "readStr:::="<<readStr<<endl;

}
infile.close();

}
else
{
cout << "Error opening file";
}
return true;

}
but on compilation the compiler is giving an error message that

could not find the function is_open()
is it not available on Solaris compiler??

Can anyone enlighten me on that??

Jul 23 '05 #1
8 3147
am*********@gmail.com wrote:
Hi,
We are working on Solaris SunOS 5.8. We are using ifstream of iostream
namespace. The snippet is given below:

#include <iostream.h>
#include <fstream.h>

boolean readFile()
{
char readStr[256];

ifstream infile;
infile.open("123768_20010706_2001.csv");

if (infile.is_open())
{
while (infile.good())
{
infile.getline(readStr,256,'\n');
cout << "readStr:::="<<readStr<<endl;

}
infile.close();

}
else
{
cout << "Error opening file";
}
return true;

}
but on compilation the compiler is giving an error message that

could not find the function is_open()
is it not available on Solaris compiler??

Can anyone enlighten me on that??


I'm not sure if is_open() is standard or not. gcc seems to have it,
can't find it in Stroustrup. In any case, it seems somewhat redun-
dant, since if open() fails it sets the stream's failbit, which will
be tested by good() anyway...

(BTW what is "boolean"?)

HTH,

--
Lionel B

Jul 23 '05 #2
"Lionel B" <me@privacy.net> wrote in message
news:42***********************@news.sunsite.dk...
am*********@gmail.com wrote:
We are working on Solaris SunOS 5.8. We are using ifstream of iostream
namespace. The snippet is given below:

#include <iostream.h>
#include <fstream.h>

boolean readFile()
{
char readStr[256];

ifstream infile;
infile.open("123768_20010706_2001.csv");

if (infile.is_open())
{
while (infile.good())
{
infile.getline(readStr,256,'\n');
cout << "readStr:::="<<readStr<<endl;

}
infile.close();

}
else
{
cout << "Error opening file";
}
return true;

}
but on compilation the compiler is giving an error message that

could not find the function is_open()
is it not available on Solaris compiler??

Can anyone enlighten me on that??


I'm not sure if is_open() is standard or not. gcc seems to have it,
can't find it in Stroustrup. In any case, it seems somewhat redun-
dant, since if open() fails it sets the stream's failbit, which will
be tested by good() anyway...


is_open is required by the C++ Standard.
(BTW what is "boolean"?)


It's a value of type bool, which stores either true or false.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 23 '05 #3
is_open() is in the standard.

It is also in TC++PL, but the index let me (us?) down. Thanks for
pointing it out. It's mentioned as a member of basic_ostream on pg 638
and of basic_streambuf on page 648.

I suspect that the reason I give it so short shift is that I tend to
use
if(os) ...
rather than
if(os.is_open())

A boolean is a value used for logocal computations. In C++, it means a
value of type bool

-- Bjarne Stroustrup; http://www.research.att.com/~bs

Jul 23 '05 #4
On 5 Jul 2005 23:27:18 -0700, am*********@gmail.com wrote:
Hi,
We are working on Solaris SunOS 5.8. We are using ifstream of iostream
namespace. The snippet is given below:

#include <iostream.h>
#include <fstream.h>
The *.h headers are deprecated. But I have never worked on Solaris, so
maybe this is an old version of their cc? Nowadays, one uses:

#include <iostream>
#include <fstream>

Try it and see if it clears up the problem.

[BTW, is <istream> automatically included by <iostream>? I seem to
recall that <ostream> isn't necessarily included by all
implementations ...]
boolean readFile()
{
char readStr[256];

ifstream infile;
infile.open("123768_20010706_2001.csv");

if (infile.is_open())
{
while (infile.good())
{
infile.getline(readStr,256,'\n');
cout << "readStr:::="<<readStr<<endl;

}
infile.close();

}
else
{
cout << "Error opening file";
}
return true;

}
but on compilation the compiler is giving an error message that

could not find the function is_open()
is it not available on Solaris compiler??

Can anyone enlighten me on that??


--
Bob Hairgrove
No**********@Home.com
Jul 23 '05 #5
bjarne wrote:

is_open() is in the standard.

I suspect that the reason I give it so short shift is that I tend to
use
if(os) ...
rather than
if(os.is_open())


I fell into a trap using this syntax, recently:

ifstream f;
if (foo())
f.open("pathname");

if (f)
{
// read stuff from file....
}
else
cout << "File is not open.\n";

The problem was that if you never try to open the fstream,
it never gets any fail bits set, so (f) evaluates to true,
wherewas f.is_open() would have been false.

Jul 23 '05 #6
P.J. Plauger wrote:
"Lionel B" <me@privacy.net> wrote in message
news:42***********************@news.sunsite.dk...
am*********@gmail.com wrote:

/.../


I'm not sure if is_open() is standard or not. gcc seems to have it,
can't find it in Stroustrup. In any case, it seems somewhat redun-
dant, since if open() fails it sets the stream's failbit, which will
be tested by good() anyway...


is_open is required by the C++ Standard.


Yup.
(BTW what is "boolean"?)


It's a value of type bool, which stores either true or false.


I know what the word "boolean" means; however AFAIK it is not a standard
type and doesn't appear to have been defined in the OP's code - why not
just use "bool"?

--
Lionel B

Jul 23 '05 #7
"Lionel B" <me@privacy.net> wrote in message
news:42***********************@news.sunsite.dk...
(BTW what is "boolean"?)


It's a value of type bool, which stores either true or false.


I know what the word "boolean" means; however AFAIK it is not a standard
type and doesn't appear to have been defined in the OP's code - why not
just use "bool"?


Because of a very long tradition of using the term Boolean in math?
George Boole (http://www.kerryr.net/pioneers/boole.htm) developed
modern two-value logic early in the 19th century. We use the term
Boolean in his honor to describe his math. bool is a recent
degenerate variant used in some programming languages; and boolean
is an inevitable back formation.

HTH,

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 23 '05 #8
P.J. Plauger wrote:
"Lionel B" <me@privacy.net> wrote in message
news:42***********************@news.sunsite.dk...
(BTW what is "boolean"?)

It's a value of type bool, which stores either true or false.


I know what the word "boolean" means; however AFAIK it is not a
standard type and doesn't appear to have been defined in the OP's
code - why not just use "bool"?


Because of a very long tradition of using the term Boolean in math?
George Boole (http://www.kerryr.net/pioneers/boole.htm) developed
modern two-value logic early in the 19th century.


Hopefully I know that... I have a PhD in maths :-)

--
Lionel B

Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Pete H | last post: by
4 posts views Thread by Gunnar | last post: by
4 posts views Thread by hall | last post: by
1 post views Thread by Alex Vinokur | last post: by
7 posts views Thread by shawn | last post: by
5 posts views Thread by Kamran | last post: by
6 posts views Thread by Gary Wessle | last post: by
4 posts views Thread by Chris Forone | last post: by
11 posts views Thread by adramolek | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.