473,395 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3349
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pete H | last post by:
I am trying to use the same ifstream object to open two files. I will eventually want to open many with a loop. The first file opens fine, but the second has a problem. In my test I try to open two...
4
by: Gunnar | last post by:
Hello. The (stupid) code below does not compile with the message In method `istream::istream(const istream &)': /usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/streambuf.h:128:...
4
by: hall | last post by:
Hi. I ran across a bug in one of my problems and after spending some time tracking it down i found that the problem arose in a piece of code that essentially did this: ----------- ifstream...
1
by: Alex Vinokur | last post by:
I have several questins concerning a program below. ------ foo.cpp : BEGIN ------ #include <cassert> #include <cstdlib> #include <iostream> #include <fstream> using namespace std; int...
7
by: shawn | last post by:
Hi All, Am using MSVC6 compiler on a WinXP machine. Am trying to read a file using std::ofstream; the problem is that Tofstream.is_open() fails and Tifstream.rdstate() returns "2" which...
5
by: Kamran | last post by:
Hi, I am having problem using std::ifstream in my code under solaris. Everything works fine on linux but the same thing i.e. trying to read a binary file and fill in a struct result in complete...
6
by: Gary Wessle | last post by:
hi I have a code, the part which is troubling goes like this **************************************************************** #include <istream> #include <ostream> #include <fstream>
4
by: Chris Forone | last post by:
hello group, why have i to bracket the second ctor param in the following example? thx & hand, chris #include <fstream> #include <iterator> int main()
11
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.