- The first form of get()is without parameters. This returns the value of the charac-
ter found, and will return EOF(end of file) if the end of the file is reached.
The second form of get()takes a character reference as its parameter; that charac-
ter is filled with the next character in the input stream. The return value is an
iostreamobject.
The third form of get()takes an array, a maximum number of characters to get,
and a terminating character. This form of get()fills the array with up to one fewer
characters than the maximum (appending null) unless it reads the terminating char-
acter, in which case it immediately writes a null and leaves the terminating charac-
ter in the buffer.
4.cin.read()is used for reading binary data structures.
getline()is used to read from the istream’s buffer. - Wide enough to display the entire number.
- A reference to an istreamobject.
- The filename to be opened.
- ios::ateplaces you at the end of the file, but you can write data anywhere in the
file.
Exercises
- The following is one possible solution:
0: // Ex1701.cpp
1: #include
2: int main()
3: {
4: int x;
5: std::cout << “Enter a number: “;
6: std::cin >> x;
7: std::cout << “You entered: “ << x << std::endl;
8: std::cerr << “Uh oh, this to cerr!” << std::endl;
9: std::clog << “Uh oh, this to clog!” << std::endl;
10: return 0;
11: } - The following is one possible solution:
0: // Ex1702.cpp
1: #include
2: int main()
3: {
4: char name[80];
5: std::cout << “Enter your full name: “;
6: std::cin.getline(name,80);
7: std::cout << “\nYou entered: “ << name << std::endl;
8: return 0;
9: }
860 Appendix D
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 860