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 () { std::ios::sync_with_stdio(false); fstream filestr("/tmp/test.txt", ios::in|ios::out|ios::app); if (filestr.is_open()) { cout << "File successfully open" << endl; filestr << "Help wanted!" << endl; filestr.close(); } else { 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): gcc-c++-3.4.1-4 How reproducible: Always 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:
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: http://www-cdf.fnal.gov/offline/zoom/defects/c++-cd2/lib-iostreams.html 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."
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.