Class Notes (806,817)
Canada (492,453)
CS 138 (14)
Lecture 4

Data Lecture 4.docx

4 Pages
Unlock Document

University of Waterloo
Computer Science
CS 138
Michael Godfrey

Data Lecture 4 January 17, 2013 Manipulate I/O  Look at  Justification  Padding  Some random syntax o cin get input o cout print output o cerr print error messages o << write output o >> get input  Input and whitespace o cin>>foo>bar;  42----------43  string line; getline(cin, line);  Input and EOF o eof()  True if EOF o fail()  True if EOF o Equivalent statements:  if(istr)  if(! int main (--) { double sum=0; int count=0; while (true) { double next; while (cin>>next) { sum +=next; count++; } } ... }  File I/O o  ifstream  ofstream o Can’t use filename directly o Associate it with a stream  Eg: ifstream ifstr(“foo”); o Stream cxrs expects char* and not strings  Need to check that stream creation was successful  Check fail()  Immediately after creation  If failed, then fail() will return TRUE  Can use >> << as before #include #include int main (int argc, char* arg[]) { if (!argc>1) { cerr<>grade>>name) { if (grade >=50) { pass<
More Less

Related notes for CS 138

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.