Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
stringbuf.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, endl
30#include <sstream> // for istringstream, ostringstream
31#include <string> // for string
32
33#include <examples.h>
34
35
36int main ()
37{
38 // create a read/write string-stream object on tiny char
39 // and attach it to an ostringstream object
40 std::ostringstream out_1 (std::ios::in | std::ios::out);
41
42 // tie the istream object to the ostringstream object
43 std::istream in_1 (out_1.rdbuf ());
44
45 // output to out_1
46 out_1 << "Here is the first ouput";
47
48 // create a string object on tiny char
49 std::string string_ex = "L'heure est grave!";
50
51 // open a read only stringstream object and initialize it
52 std::istringstream in_2 (string_ex);
53
54 // output in_1 to the standard output
55 std::cout << in_1.rdbuf () << std::endl;
56
57 // reposition in_1 at the beginning
58 in_1.seekg (0);
59
60 // output in_2 to the standard output
61 std::cout << in_2.rdbuf () << std::endl;
62
63 // reposition in_2 at the beginning
64 in_2.seekg (0);
65
66 // get the current put position (equivalent to out_1.tellp ())
67 std::stringbuf::pos_type pos =
68 out_1.rdbuf ()->pubseekoff (0, std::ios::cur, std::ios::out);
69
70 // append the content of the stringbuf pointed to by in_2
71 // to the one pointed at by out_1
72 out_1 << ' ' << in_2.rdbuf ();
73
74 // output in_1 to the standard output
75 std::cout << in_1.rdbuf () << std::endl;
76
77 // position the get sequence (equivalent to in_1.seekg (pos))
78 in_1.rdbuf ()->pubseekpos (pos, std::ios::in);
79
80 // output "L'heure est grave!"
81 std::cout << in_1.rdbuf () << std::endl;
82
83 return 0;
84}
#define pos
Definition 17.names.cpp:518
int main()
Definition stringbuf.cpp:36