Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
27.stringbuf.members.stdcxx-427.cpp
Go to the documentation of this file.
1
27#include <cassert>
28#include <cstdio>
29#include <sstream>
30
31int main ()
32{
33 struct Buf: std::stringbuf {
34 Buf (std::string s, std::ios::openmode m)
35 : std::stringbuf (s, m) { }
36
37 void setget (int beg, int cur, int end) {
38 setg (eback () + beg, eback () + cur, eback () + end);
39 }
40
41 void setput (int beg, int cur, int end) {
42 setp (pbase () + beg, pbase () + end);
43 pbump (cur);
44 }
45 };
46
47 {
48 Buf buf ("abcde", std::ios::in);
49 buf.setget (1, 2, 4);
50 std::printf ("%s\n", buf.str ().c_str ());
51 assert ("bcd" == buf.str ());
52 }
53 {
54 Buf buf ("abcde", std::ios::out);
55 buf.setput (1, 2, 4);
56 std::printf ("%s\n", buf.str ().c_str ());
57 assert ("bcde" == buf.str ());
58 }
59 {
60 Buf buf ("abcde", std::ios::openmode ());
61 std::printf ("%s\n", buf.str ().c_str ());
62 assert ("" == buf.str ());
63 }
64}
#define m
Definition 17.names.cpp:129
#define buf
Definition 17.names.cpp:452
#define s
const int end
const int cur
#define assert(expr)
Definition _cassert.h:40