Author: sebor
Date: Thu Nov 17 08:12:37 2005
New Revision: 345275
URL: http://svn.apache.org/viewcvs?rev=345275&view=rev
Log:
2005-11-17 Martin Sebor <[EMAIL PROTECTED]>
* strstream.cpp: Output line numbers and the numbers of extracted
characters to make example more interesting.
* strstream.out: Changed to match the existing output.
Modified:
incubator/stdcxx/trunk/examples/manual/out/strstream.out
incubator/stdcxx/trunk/examples/manual/strstream.cpp
Modified: incubator/stdcxx/trunk/examples/manual/out/strstream.out
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/examples/manual/out/strstream.out?rev=345275&r1=345274&r2=345275&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/out/strstream.out (original)
+++ incubator/stdcxx/trunk/examples/manual/out/strstream.out Thu Nov 17
08:12:37 2005
@@ -1,11 +1,15 @@
+Full text, 104 characters:
+ Dieses ist die Geschichte eines Mannes.
+ C'est l'histoire d'un homme.
+ This is the story of a man.
-Deutsch:
-Dieses ist die Geschichte eines Mannes.
-Francais:
-C'est l'histoire d'un homme.
-English:
-This is the story of a man.
+Line 1, 42 characters:
+ Dieses ist die Geschichte eines Mannes.
+Line 2, 31 characters:
+ C'est l'histoire d'un homme.
+Line 3, 30 characters:
+ This is the story of a man.
+Line 4, 1 character (no newline):
+ '\0'
-Dieses ist die Geschichte eines Mannes.
-C'est l'histoire d'un homme.
-This is the story of a man.
+Extracted 104 characters.
Modified: incubator/stdcxx/trunk/examples/manual/strstream.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/examples/manual/strstream.cpp?rev=345275&r1=345274&r2=345275&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/strstream.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/strstream.cpp Thu Nov 17 08:12:37
2005
@@ -2,7 +2,7 @@
*
* strstream.cpp - strstream example.
*
- * $Id: //stdlib/dev/examples/stdlib/manual/strstream.cpp#12 $
+ * $Id$
*
***************************************************************************
*
@@ -30,34 +30,43 @@
// create a bi-directional strstream object
std::strstream inout;
- // write out three lines to the stream
- inout << "Dieses ist die Geschichte eines Mannes.\n"
- << "C'est l'histoire d'un homme.\n"
- << "This is the story of a man."
+ // write three complete lines of text to the stream
+ inout << " Dieses ist die Geschichte eines Mannes.\n"
+ << " C'est l'histoire d'un homme.\n"
+ << " This is the story of a man.\n"
<< std::ends;
char line [80];
- // extract the first line
- inout.getline (line, sizeof line);
+ // output the entire contents of the stream object to stdout
+ std::cout << "Full text, " << inout.pcount ()
+ << " characters:\n" << inout.str ();
+
+ // keep track of the number of characters extracted by getline
+ int gcount = 0;
+
+ // extract lines from the stream, one at a time
+ for (int i = 1; inout.getline (line, sizeof line); ++i) {
+
+ // increment the number of extracted characters
+ gcount += inout.gcount ();
+
+ // write out the line number and its length
+ std::cout << "\nLine " << i << ", " << inout.gcount ();
+
+ if ('\0' == *line) {
+ // incomplete line (missing newline character)
+ std::cout << " character (no newline):\n"
+ << " '\\0'\n";
+ }
+ else {
+ // output the line to stdout
+ std::cout << " characters:\n" << line;
+ }
+ }
- // output the first line to stdout
- std::cout << "\nDeutsch:\n" << line;
-
- // extract the second line
- inout.getline (line, sizeof line);
-
- // output the second line to stdout
- std::cout << "\nFrancais:\n" << line;
-
- // extract the third line
- inout.getline (line, sizeof line);
-
- // output the third line to stdout
- std::cout << "\nEnglish:\n" << line;
+ // write out the total number of extracted characters
+ std::cout << "\nExtracted " << gcount << " characters.\n";
- // output the contents of the stream object to stdout
- std::cout << "\n\n" << inout.str () << '\n';
-
return 0;
}