|
1
|
- Instructor: Brian M. Dennis
- Teaching Assistants:
- Tom Lechner, Bin Lin, Rachel Goldsborough
- http://www.cs.northwestern.edu/~bmd/cs211/
|
|
2
|
- Already using them
- cout << "foo";
- cin >> some_int;
- Today, more sophisticated uses
- Participate in a hierarchy of classes
- Forward reference inheritance
|
|
3
|
|
|
4
|
- ostream
- put, takes a char, returns ostream ref
- istream
- get, no args returns next char
- get, char ref stores next char
- get, char*, size, delimeter
- up to terminator or buf size
- getline, no args,
|
|
5
|
|
|
6
|
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- int main() {
- const int SIZE = 80;
- char buf1[SIZE];
- char buf2[SIZE];
- cout << "Enter a sentence:" << endl;
- cin >> buf1;
- cout << "\nThe string read with cin was:" << endl
- << buf1 << endl << endl;
|
|
7
|
- cin.get(buf2, SIZE);
- cout << "The string read with cin.get was:" <<
endl
- << buf2 << endl;
- cin.getline(buf2, SIZE);
- cout << "\nThe sentence read with getline is:" <<
endl
- << buf2 << endl;
- return 0;
- }
|
|
8
|
- output
- write, member function
- cout.write(buf);
- cout.write(buf, size)
- input
- read, member function
- cout.read(buf, sz);
|
|
9
|
- Integer output base
- dec, oct, hex manip
- setbase member function
- Floating point precision
- # of right digits displayed
- setprecision manip
- precision member function
- Field manipulations
- width member func, setw manip
- skipws, noskipws
- left, right
- showbase, noshowbase
- showpoint, noshowpoint
- scientific, fixed
|
|
10
|
- cin.eof()
- cin.fail()
- cin.bad()
- cin.good()
- cout.rdstate()
- cin.clear()
- operator!
|
|
11
|
|