g++ 4.6.3 on Ubuntu 12.04 fails to open any fstream file

Bug #1272401 reported by Patrick Nichols
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)
New
Undecided
Unassigned

Bug Description

If one declares a fstream class the file will never be opened.
A simple file to illustrate the bug is listed below.

#include <iostream>
#include <fstream> // std::ofstream
#include <iomanip>
#include <string>
using namespace std;

int main () {

    fstream outfile;
    outfile.open ("test.txt");
    if (outfile.is_open()) {
        outfile.write ("This is an apple",16);
        string t;
        outfile >> t;
        cerr << t << endl;
        long pos = outfile.tellp();
        outfile.seekp (pos-7);
        outfile.write (" sam",4);
        string s;
        outfile.seekg(0);
        outfile >> s;
        cerr << s << endl;
    }else{
        cerr << "error opening file tst.txt!\n";
    }

    outfile.close();

    return 0;
}

g++ --version command yields:
patrick@bucephalus:~/test$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Thank you!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.