istream_iterator |
An iterator that reads items in a typesafe manner from a standard input stream.
#include <iterator>
template< class T, class Distance >
class istream_iterator : public input_iterator< T, Distance >
true
if the iterator has the same stream and state as iter
.true
if the iterator does not have the same stream or state as iter
.
#include <iostream>
#include <iterator>
void
main()
{
char buffer[ 100 ];
int i = 0;
cin.unsetf( ios::skipws ); // Disable white-space skipping.
cout << "Please enter a string: ";
istream_iterator< char, ptrdiff_t > s( cin );
while ( *s != `\n' )
buffer[ i++ ] = *s++;
buffer[ i ] = `\0'; // Null terminate buffer.
cout << "read " << buffer << "\n";
}
Please enter a string: truth
read truth
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.