|
|
A useful extractor, but one that must be used with caution, takes a char* second argument. For example,
char p[100]; cin >> p;skips whitespace on cin, extracts visible characters from cin and copies them into p until another whitespace character is encountered. Finally it stores a terminating null (0) character. The char* extractor must be used with caution because if there are too many visible characters in the istream, the array will overflow.
The above example is more carefully written as:
char p[100] ; cin.width(sizeof(p)) ; cin >> p ;There are very few circumstances (perhaps there are none at all) in which it is appropriate to use the char* extractor without setting the ``width'' of the istream.
To make specifying a width more convenient, the setw manipulator (declared in iomanip.h) may be used. The above example is equivalent to:
char p[100] ; cin >> setw(sizeof(p)) >> p ;