C++ STL istreambuf_iterator::operator++, increment program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Using the C++ istreambuf_iterator::operator++ to either returns the next character from the input stream or copies the object before incrementing it and returns the copy in C++ programming
To show: How to use the C++ istreambuf_iterator, operator++ to either returns the next character from the input stream or copies the object before incrementing it and returns the copy in C++ programming
// C++ STL istreambuf_iterator, operator++, increment
#include <iterator>
#include <iostream>
using namespace std;
int main(void)
{
cout<<"Type a line of text & enter to output it, with stream\n"
<<"buffer iterators, repeat as many times as desired,\n"
<<"then keystroke ctrl-Z Enter to exit program: \n";
istreambuf_iterator<char> inpos(cin);
istreambuf_iterator<char> endpos;
ostreambuf_iterator<char> outpos(cout);
while(inpos != endpos)
{
*outpos = *inpos;
// istreambuf_iterator increment
++inpos;
++outpos;
}
return 0;
}
Output examples:
Type a line of text & enter to output it, with stream
buffer iterators, repeat as many times as desired,
then keystroke ctrl-Z Enter to exit program:
This is a line of text
This is a line of text
Another line of string
Another line of string
read from standard input and print on the standard output
read from standard input and print on the standard output
stream...buffer....iterator
stream...buffer....iterator
ending
ending
^Z
Press any key to continue . . .