Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
21.string.stdcxx-231.cpp
Go to the documentation of this file.
1
27#include <cassert>
28#include <string>
29#include <sstream>
30
31int main ()
32{
33 std::string s (100, 's');
34
35 const std::string::size_type n = s.capacity ();
36 const std::string::const_pointer p = s.c_str ();
37
38 // verify getline(), clear(), erase() and replace() do not
39 // unnecessarily resize or reallocate the data buffer
40 std::istringstream is ("hello world");
41 std::getline (is, s);
42 assert (s.capacity () == n);
43 assert (s.c_str () == p);
44
45 s.clear ();
46 assert (s.capacity () == n);
47 assert (s.c_str () == p);
48
49 s.erase ();
50 assert (s.capacity () == n);
51 assert (s.c_str () == p);
52
53 s.replace (0, std::string::npos, "1", 0);
54 assert (s.capacity () == n);
55 assert (s.c_str () == p);
56
57 return 0;
58}
59
#define s
#define n
Definition 17.names.cpp:130
#define p
Definition 17.names.cpp:132
int main()
#define assert(expr)
Definition _cassert.h:40