Il seguente programma (giocattolo) restituisce cose diverse quando è collegato a libstdC++ e libC++. Si tratta di un bug in libC++ o non capisco come funziona isream eof()? Ho provato a farlo usando g ++ su linux e mac os x e clang su mac os x, con e senza -std = C++ 0x. Ho avuto l'impressione che eof() non restituisca true fino a quando un tentativo di lettura (di get() o qualcos'altro) fallisce. Ecco come si comporta libstdC++, ma non come si comporta libC++.discrepanza di istream eof tra libC++ e libstdC++
#include <iostream>
#include <sstream>
int main() {
std::stringstream s;
s << "a";
std::cout << "EOF? " << (s.eof() ? "T" : "F") << std::endl;
std::cout << "get: " << s.get() << std::endl;
std::cout << "EOF? " << (s.eof() ? "T" : "F") << std::endl;
return 0;
}
Thor:~$ g++ test.cpp
Thor:~$ ./a.out
EOF? F
get: 97
EOF? F
Thor:~$ clang++ -std=c++0x -stdlib=libstdc++ test.cpp
Thor:~$ ./a.out
EOF? F
get: 97
EOF? F
Thor:~$ clang++ -std=c++0x -stdlib=libc++ test.cpp
Thor:~$ ./a.out
EOF? F
get: 97
EOF? T
Thor:~$ clang++ -stdlib=libc++ test.cpp
Thor:~$ ./a.out
EOF? F
get: 97
EOF? T
Avrei dovuto controllare altre risposte prima! – Cubbi