File Stream Open Problem with g++ 3.3.3 and libstdc++.so.5

Subrata Basak subrata-basak@mediaring.com
Mon Mar 29 10:26:00 GMT 2004


Hi Paolo

As per your suggession, I used "ofstream" instead of "ifstream"
in my code, but unfortunately, the result was same before, after
254 successful streams openning, assertion occured, but I am 
supposed to open 1000 streams to the same file "boo".

NOTE: I have one existing file named "boo" in the same directory of a.out.

My Code :
==========================================
#include <assert.h>
#include <fstream>
#include <iostream>
#include <string>

const int MAX_STREAM = 1000;

using namespace std;

int main(int argc, char* argv[])
{
        ofstream in[MAX_STREAM];
        string file("boo");

        for ( int i=0; i != MAX_STREAM; i++ )
        {
                in[i].open(file.c_str());
                cout << "i : " << i << endl;
                assert(in[i]);
        }
        return 0;
}
=========================================

Please let me know your opinion.

With Very Best Regards

Subrata Basak




-----Original Message-----
From: Paolo Carlini [mailto:pcarlini@suse.de]
Sent: Monday, March 29, 2004 5:49 PM
To: Subrata Basak
Cc: 'gcc-libstdc++'
Subject: Re: File Stream Open Problem with g++ 3.3.3 and libstdc++.so.5


Hi,

according to the ISO standard, now closely tracked, the default
open mode of ifstream is "in", the equivalent of C "r", therefore
_file must exist_: indeed, changing your snippet to use ofstream
leads to the expected behavior.

Paolo.

P.S. gcc-help is much more suited for this kind of doubts.



More information about the Libstdc++ mailing list