This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fstream bug ??


I have a behaviour with g++-4.4.3 that I do not understand...
The following program does not do what I would expect:

#include <string>
#include <iostream>
#include <fstream>
#include <unistd.h>

int main() {
    std::string str;
    std::fstream rw("/tmp/toto");
    rw >> str;
    std::cout << str << std::endl;
    rw << "Streams are complicated." << std::endl;
    sleep(1);
    return 0;
}

This program reads whatever is the first word in the file /tmp/toto but never writes
the "Streams are complicated." (checked with strace).


If I swap the read and the write, ie:

int main() {
    std::string str;
    std::fstream rw("/tmp/toto");
    rw << "Streams are complicated." << std::endl;
    rw >> str;
    std::cout << str << std::endl;
    sleep(1);
    return 0;
}

then it writes but never reads...
I use streams a lot, but it's probably the first time I use bidirectional streams, so
there might be sthg I do not understand, but at first sight it is really surprising
and looks like a bug. Can someone confirm this before I file it in bugzilla ??


Theo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]