Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why is stream fail() bit set?

Reply
Thread Tools

Why is stream fail() bit set?

 
 
Dilip
Guest
Posts: n/a
 
      10-26-2006

This thing is driving me nuts.

why would a simple output file stream like this:

ofstream ofs;
ofs.open("c:\temp\somefile.txt")

set the fail bit?

calling ofs.fail() right after the open is returning true.

 
Reply With Quote
 
 
 
 
Moonlit
Guest
Posts: n/a
 
      10-26-2006
Hi,

\t
means tabstop
use either
c:/temp/somefile.txt
or
c:\\temp\\somefile.txt

--


Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Dilip" <> wrote in message
news: oups.com...
>
> This thing is driving me nuts.
>
> why would a simple output file stream like this:
>
> ofstream ofs;
> ofs.open("c:\temp\somefile.txt")
>
> set the fail bit?
>
> calling ofs.fail() right after the open is returning true.
>



 
Reply With Quote
 
 
 
 
Dilip
Guest
Posts: n/a
 
      10-26-2006

Moonlit wrote:
> Hi,
>
> \t
> means tabstop
> use either
> c:/temp/somefile.txt
> or
> c:\\temp\\somefile.txt


That was just an example. I know a backslash inside a string needs to
be escaped. The file does get created. Its just that I can't write
anythng into it because fail() returns true and I can't figure out why.
The low level OS _open (or whatever) call seems to successfully create
the file everytime. Somewhere after that I don't know why that bit is
getting set.

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      10-26-2006
Dilip wrote:
> This thing is driving me nuts.
>
> why would a simple output file stream like this:
>
> ofstream ofs;
> ofs.open("c:\temp\somefile.txt")


Will Windoze let you put tabs in a file name? Remember
\ is special in C++.
 
Reply With Quote
 
Moonlit
Guest
Posts: n/a
 
      10-26-2006
Hi,

You should post the code that you used not something you made up.

The code you posted doesn't work neither on windows nor unix/linux

If you want help post your complete code cut and paste.

--


Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Dilip" <> wrote in message
news: ups.com...
>
> Moonlit wrote:
>> Hi,
>>
>> \t
>> means tabstop
>> use either
>> c:/temp/somefile.txt
>> or
>> c:\\temp\\somefile.txt

>
> That was just an example. I know a backslash inside a string needs to
> be escaped. The file does get created. Its just that I can't write
> anythng into it because fail() returns true and I can't figure out why.
> The low level OS _open (or whatever) call seems to successfully create
> the file everytime. Somewhere after that I don't know why that bit is
> getting set.
>



 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      10-26-2006

Dilip wrote:
> This thing is driving me nuts.
>
> why would a simple output file stream like this:
>
> ofstream ofs;
> ofs.open("c:\temp\somefile.txt")
>
> set the fail bit?
>
> calling ofs.fail() right after the open is returning true.


If you create the file successfully, assuming the OS perimissions are
set appropritely, you should be able to stream to the file. But since
you aren't showing how you do that, nobody can help.

 
Reply With Quote
 
Dilip
Guest
Posts: n/a
 
      10-27-2006
On Oct 26, 5:54 pm, "Salt_Peter" <pj_h...@yahoo.com> wrote:
> Dilip wrote:
> > This thing is driving me nuts.

>
> > why would a simple output file stream like this:

>
> > ofstream ofs;
> > ofs.open("c:\temp\somefile.txt")

>
> > set the fail bit?

>
> > calling ofs.fail() right after the open is returning true.If you create the file successfully, assuming the OS perimissions are

> set appropritely, you should be able to stream to the file. But since
> you aren't showing how you do that, nobody can help.


I am not streaming to the file yet. Before I decide to do that I do a
check to see if the stream is in usable state by calling ofs.fail().
Because fail() is returning true I am not going ahead with the
streaming. I am trying to figure why fail() returns true when the file
got created successfully.

 
Reply With Quote
 
Dilip
Guest
Posts: n/a
 
      10-27-2006


On Oct 26, 5:30 pm, Ron Natalie <r...@spamcop.net> wrote:
> Dilip wrote:
> > This thing is driving me nuts.

>
> > why would a simple output file stream like this:

>
> > ofstream ofs;
> > ofs.open("c:\temp\somefile.txt")Will Windoze let you put tabs in a file name? Remember

> \ is special in C++.


That was just a typo in the example. The real code gets the file name
from elsewhere. As I repeatedly stated in other threads the file
*does* get created successfully right after the .open call. I just
don't understand why fail() on the stream returns true after that.

 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      10-27-2006
On 26 Oct 2006 15:27:20 -0700 in comp.lang.c++, "Dilip"
<> wrote,
>That was just an example. I know a backslash inside a string needs to
>be escaped.


Then it's not a very good example, is it?

> The file does get created. Its just that I can't write
>anythng into it because fail() returns true and I can't figure out why.


What does perror() say?

 
Reply With Quote
 
Dilip
Guest
Posts: n/a
 
      10-27-2006
On Oct 26, 7:36 pm, David Harmon <sou...@netcom.com> wrote:
> On 26 Oct 2006 15:27:20 -0700 in comp.lang.c++, "Dilip"
> <rdil...@lycos.com> wrote,
> > The file does get created. Its just that I can't write
> >anythng into it because fail() returns true and I can't figure out why.


> What does perror() say?


Doesn't perror write to stderr? My app is not a console application.
Is there any other way to check? Or should I redirect stderr to
elsewhere and track down the error message? That seems awfully
complicated.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Why no diagnostic for stream << stream? Anand Hariharan C++ 2 03-18-2009 03:23 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57