Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
27.ostream.unformatted.stdcxx-626.cpp
Go to the documentation of this file.
1
29#include <cassert>
30#include <ostream>
31
33
34struct MyBuf: std::streambuf
35{
36 virtual int sync () {
37 ++sync_calls;
38 return -1;
39 }
40};
41
42
43int main ()
44{
45 MyBuf buf;
46
47 std::ostream os (&buf);
48
49 // verify that ostream::flush() doesn't call streambuf::sync()
50 // when the state of the stream isn't good
51
52 os.setstate (os.badbit);
53
54 os.flush ();
55
56 assert (0 == sync_calls);
57
58 os.setstate (os.eofbit);
59
60 os.flush ();
61
62 assert (0 == sync_calls);
63
64 os.setstate (os.failbit);
65
66 os.flush ();
67
68 assert (0 == sync_calls);
69
70 return 0;
71}
#define os
Definition 17.names.cpp:511
#define buf
Definition 17.names.cpp:452
#define assert(expr)
Definition _cassert.h:40