Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
27.stringbuf.str.stdcxx-514.cpp
Go to the documentation of this file.
1
27#include <sstream> // for stringbuf
28#include <memory> // for allocator
29
30#include <cassert> // for assert()
31
32char extbuf [3];
33
34struct MyAlloc : std::allocator <char>
35{
36 pointer allocate (size_type __n, std::allocator<void>::const_pointer = 0) {
37 return new char [__n];
38 }
39
40 void deallocate (pointer __p, size_type)
41 {
42 assert (extbuf != __p);
43 delete [] __p;
44 }
45};
46
47int main ()
48{
49 std::basic_stringbuf <char, std::char_traits <char>, MyAlloc> sbuf;
50
51 sbuf.pubsetbuf (extbuf, sizeof (extbuf));
52
53 const char* str = "abcdef";
54 sbuf.str (str);
55 assert (sbuf.str () == str);
56
57 return 0;
58}
#define assert(expr)
Definition _cassert.h:40
const char * str
Definition exec.cpp:170
pointer allocate(size_type __n, std::allocator< void >::const_pointer=0)
void deallocate(pointer __p, size_type)