1 2 3 4 5 6 7 8 9

int i;
while(TRUE) {
if (cin >> i)
cout << i;
else break;

*This loop will copy integers from cin to cout until the end of file is reached
or a non-integer appears on cin
*We could convert this into a template function that copies any type
of value from an istream to an ostream
template <class T>
void iocopy (T z, istream& is, ostream& os)
while (is >> z) os << z;



Even though we don't really need to pass z to this function, we need to have it as a parameter, otherwise the iocopy function won't compile The standard input operations skip white space the same way that the C input functions do. For most applications this is okay, since we don't care about the white space between values

23 March, 1998

Page 2