CS253

This file defines the header for each page. An optional "icon" image (I use the textbook):

Replace this with info about this class:

CS253: Problem Solving with C++

Spring 2014

Heckendorn

Links to the various pages for this class:

Wish I could do this: * Schedule

Heckendorn’s Law

Heckendorn’s Law is based on a saying of the great Robert Heckendorn:

Never emit a constant error message

That is, don’t do this:

    ifstream in(pwfile);
    if (!in) {
        cerr << "Bad file\n";
        return 1;
    }

Imagine the frustration of the user who reads this uninformative message. Which file is bad? What was wrong with it? What was the program trying to do with the file? What program was running, anyway?

There’s always more information that you can provide:

Here’s how to do it:

    #include <iostream>
    #include <fstream>          // for ifstream
    #include <cstdio>           // for perror

    using namespace std;

    int main(int /* argc */, char *argv[]) {
        const char pwfile[] = "/etc/shadow";      // Why not a std::string?

        ifstream in(pwfile);
        if (!in) {
            cerr << argv[0] << ": can’t read shadow password file ";
            perror(pwfile);
            return 1;
        }

        return 0;
    }

Modified: 2014-02-02T10:17

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building