Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
strstream.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, ends
30#include <strstream> // for sstream
31
32#include <examples.h>
33
34
35int main ()
36{
37 // create a bi-directional strstream object
38 std::strstream inout;
39
40 // write three complete lines of text to the stream
41 inout << " Dieses ist die Geschichte eines Mannes.\n"
42 << " C'est l'histoire d'un homme.\n"
43 << " This is the story of a man.\n"
44 << std::ends;
45
46 char line [80];
47
48 // output the entire contents of the stream object to stdout
49 std::cout << "Full text, " << inout.pcount ()
50 << " characters:\n" << inout.str ();
51
52 // unfreeze the streambuf so it cleans up its allocated memory
53 inout.freeze (false);
54
55 // keep track of the number of characters extracted by getline
56 std::streamsize gcount = 0;
57
58 // extract lines from the stream, one at a time
59 for (int i = 1; inout.getline (line, sizeof line); ++i) {
60
61 // increment the number of extracted characters
62 gcount += inout.gcount ();
63
64 // write out the line number and its length
65 std::cout << "\nLine " << i << ", " << inout.gcount ();
66
67 if ('\0' == *line) {
68 // incomplete line (missing newline character)
69 std::cout << " character (no newline):\n"
70 << " '\\0'\n";
71 }
72 else {
73 // output the line to stdout
74 std::cout << " characters:\n" << line;
75 }
76 }
77
78 // write out the total number of extracted characters
79 std::cout << "\nExtracted " << gcount << " characters.\n";
80
81 return 0;
82}
#define i
Definition 17.names.cpp:126
#define line
Definition 17.names.cpp:490
int main()
Definition strstream.cpp:35