std :: ws manipulator का उपयोग कर स्ट्रीम से निकालने के लिए कभी भी असफल बिट बढ़ाएं? निम्नलिखित कोड में, क्लैंग-संकलित (एक्सकोड 4.5.1 के भीतर) प्रोग्राम अंतिम दावे में विफल रहता है। ईओएफ पर स्पष्ट रूप से s >> std::ws
असफल हो जाता है। फिर भी जीसीसी 4.7.2 दावा पारित करता है। क्या सही है?क्या std :: ws फ़ाइल के अंत में विफलता बढ़ाएं?
#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;
}
मेरे लिए जीसीसी 4.6, जीसीसी 4.7 और क्लैंग 3.1 सभी प्रत्येक assert – sehe