caso estrarre da un flusso utilizzando lo std :: WS manipolatore mai alzare il bit fallire? Nel seguente codice, un programma Clang-compilato (all'interno di Xcode 4.5.1) fallisce l'asserzione finale. Evidentemente s >> std::ws
in EOF causa un errore. Eppure GCC 4.7.2 supera l'affermazione. Che è corretto?Se std :: ws genera failbit alla fine del file?
#include <iostream>
#include <sstream>
#include <cassert>
int main(int argc, const char * argv[])
{
{
// Read string with trailing ws.
std::istringstream s("test ");
std::string test;
s >> std::ws;
assert(!s.fail()); // No ws to skip, but no failure.
s >> test;
assert(test == "test");
assert(!s.fail());
s >> std::ws;
assert(!s.fail()); // No prob skipping trailing ws.
}
{
// Retry with no trailing ws.
std::istringstream s("test");
std::string test;
s >> std::ws;
assert(!s.fail()); // No ws to skip, but no failure.
s >> test;
assert(test == "test");
assert(!s.fail());
s >> std::ws;
assert(!s.fail()); // CLANG: Skipping absent ws at eof raises failbit.
}
return 0;
}
Per me gcc 4.6, gcc 4.7 e clang 3.1 tutti superano ogni asserzione – sehe