Bug 127968 - fstream fails to open a file for reading and writing or create a new file
fstream fails to open a file for reading and writing or create a new file
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2004-07-15 16:14 EDT by Guo Yang
Modified: 2007-11-30 17:10 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-08-05 14:38:02 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Guo Yang 2004-07-15 16:14:42 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040625

Description of problem:
This simple program compiled by g++ failed to run no matter
/tmp/test.txt exits or not. I always get 'Error opening file'

#include <iostream>
#include <fstream>

using namespace std;

int main () {


  fstream filestr("/tmp/test.txt", ios::in|ios::out|ios::app);

  if (filestr.is_open())
    cout << "File successfully open" << endl;
    filestr << "Help wanted!" << endl;
    cerr << "Error opening file" << endl;

  return 0;

I tried to use g++33 and g++35. Didn't work either.

But this same program compiled by Intel C++ compile 8.0 works. It also
works in Windows when compiled by Visual.NET compiler.

I also tried the same program on Redhat Linux 9.0, didn't work either.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Open an editor and type in the program and save it to test.cpp
2. g++ test.cpp
3. ./a.out

Actual Results:  I always get 'Error opening file' message. And the
file is either intact or not created. 

Expected Results:  Although I should get 'File successfully open', and
a file should be created if it doesn't exist and a sentence 'Help
Wanted' should be appended to the end of file.

Additional info:
Comment 1 Jakub Jelinek 2004-07-15 16:39:30 EDT
I don't have my ISO C++ copy handy now, will look tomorrow.
But from what I have googled around, this test is supposed to fail:
Table 11--File open modes
doesn't list there in|out|app combination and
"If mode is not some combination of flags shown in the table then the
open fails."
Comment 2 Guo Yang 2004-07-15 17:28:27 EDT
Oh, that's right. The book I am using to learn C++ doesn't state that
clearly. I thought any combination would work. Sorry. So the Intel C++
compiler doesn't stick to the standard strictly? Thank you very much.

Note You need to log in before you can comment on or make changes to this bug.