473,856 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ifstream::is_op en() 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("12 3768_20010706_2 001.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 3392
am*********@gma il.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("12 3768_20010706_2 001.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.d k...
am*********@gma il.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("12 3768_20010706_2 001.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*********@gma il.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("12 3768_20010706_2 001.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**********@Ho me.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("pathnam e");

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.d k...
am*********@gma il.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.d k...
(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.d k...
(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
8125
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 .txt files, the first text.txt reads: First seems to work... text2.txt reads:
4
2865
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: `ios::ios(const ios &)' is private Silly.cpp:15: within this context It's the function call to "foo" that does not work. My question is, what is
4
3743
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 in("in.txt"); if(!in) {cout << "error\n";} in.close(); if(!in) {cout << "error\n";} in.close(); if(!in) {cout << "error\n";}
1
2646
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 main()
7
7559
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 translates to "The system cannot find the file specified.". This is really weird because the said file am tring to read exists on the disk at the required location. SNIPPET:-
5
2687
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 junk. I use WorskShop 6.0 and my solaris version is 9. An "od -x" on my input file gives:
6
4773
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
3833
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
8155
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 fails to open a file, but nothing I read about ifstream says anything about a reliable place to get an error message. Using stdio I can simply do: FILE *f = fopen(filename, "rb"); if (!f) perror(filename);
0
9764
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10699
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10790
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9535
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7098
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4580
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.