[Bug 1272401] [NEW] g++ 4.6.3 on Ubuntu 12.04 fails to open any fstream file

Patrick Nichols patjnichols at gmail.com
Fri Jan 24 16:12:22 UTC 2014


Public bug reported:

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 at bucephalus:~/test$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Thank you!

** Affects: gcc-defaults (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.
https://bugs.launchpad.net/bugs/1272401

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

Status in “gcc-defaults” package in Ubuntu:
  New

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 at bucephalus:~/test$ g++ --version
  g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

  Thank you!

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1272401/+subscriptions



More information about the foundations-bugs mailing list