istream && istream_iterator behavior

Laurent Marzullo laurent.marzullo@be.sema.com
Fri Feb 23 03:58:00 GMT 2001


Hello all,

Here a little program


-------------------------------------------------------
void read2( istream& p_in )
{
	istream_iterator<char>	l_in_ptr( p_in );

	cout << "read2 = `" << (*l_in_ptr) << "'\n";
}


void read1( istream& p_in )
{
	istream_iterator<char>	l_in_ptr( p_in );

	cout << "read1 = `" << (*l_in_ptr) << "'\n";
	read2( p_in );
}


main( void )
{
	read1( cin );
}
-------------------------------------------------------

$ g++ essai.cpp
$ ./a.out
1234
read1 = `1'
read2 = `2'	// ?????? I was expected `1' too

May someone explain me why I've got this output and not
read2 = `1' ??

Is this a correct behavior ?

(I'm using a snapshot of gcc = gcc-20010222 & gcc-c++-20010122)

Laurent Marzullo



More information about the Libstdc++ mailing list