#include #include void foo(int & length, // string's length placed here ostream & out, // illegal to copy const string & s) { // too expensive to copy length = s.size(); out << "foo: The string's length is " << length << ".\n"; return; } int main(int argc, char *argv[]) { cout << "This silly program prints the length of the first command-line argument.\n"; if (argc == 1) { // too few command-line arguments cerr << argv[0] << ": string\n"; throw "too few command-line arguments"; } int l; // initially has garbage value foo(argv[1], l); cout << argv[1] << " has " << l << " characters.\n"; return EXIT_SUCCESS; }