Index:
[thread]
[date]
[subject]
[author]
From: Robert C. Duvall <rcd@cs.duke.edu>
To :
Date: 01 Feb 1999 23:56:26 -0500
Notes about reading characters
You may want to check out the header file ctype.h (man ctype). It
defines a number of functions to determine what kind a character is
(i.e., digit, space, etc.).
Also, a number of people are having problems with the fact that you
generally need to read one more character than the "token" to
determine where it ends (i.e., sum versus sum( ). There are several
solutions, but you should know that c++ provides a method putback()
for input streams. Check out the follwoing example which reads in
characters from stdin and until a space is detected:
char c;
while (cin.get(c))
{
if (isspace(c)) // from ctype.h
{
cin.putback(c); // put it back so it be read again
break;
}
}
rcd
--
Robert C. Duvall
Lecturer, Duke University
rcd@cs.duke.edu
Index:
[thread]
[date]
[subject]
[author]