Article View: comp.lang.modula2
Article #4157Re: Modula2's godawful IO.
From: Glen Ditchfield
Date: Wed, 13 Apr 1988 13:50
Date: Wed, 13 Apr 1988 13:50
24 lines
1822 bytes
1822 bytes
In article <547@m10ux.UUCP> rgr@m10ux.UUCP (Duke Robillard) writes:
>In article <96@lzaz.ATT.COM> bds@lzaz.ATT.COM (BRUCE SZABLAK) writes:
>>I like C++'s overloading of the << and >> operator's even better than
>>printf. It allows you to define custom print routines for each structure
>>(class) declared, and then to print (to stdout for example) you do:
>> cout << god_awful_structure_instance;
>
>Yeah, but that doesn't help me print out an error message, two strings,
>and an integer return code. I don't want to have to write a method
>for every print....
Neither would I. Fortunately for us, the i/o operators can be chained.
cout << "Error: file " << fname << ", line " << lnum
<< error_msg << "\n";
I think this is a big improvement over calls to overloaded "Print" procedures.
Details: "<<" associates left-to-right. `cout << "Error: file "' returns
cout as it's value, which is used as the left operand by `<< fname'. When
streams like cout (or the standard input, "cin") are used in an integer
context, the stream-to-int conversion returns the stream's status, so you
can write input loops like
while ( cin >> val ) { ...
If a programmer-defined type must be read or written, the programmer writes
"<<" and ">>" operators for it.
Technical Details
Message-ID:
<6366@watdragon.waterloo.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!watdragon!violet!gjditchfieldReferences:
<764@ndsuvax.UUCP> <535@m10ux.UUCP> <96@lzaz.ATT.COM> <547@m10ux.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!watdragon!violet!gjditchfield From: gjditchfield@violet.waterloo.edu (Glen Ditchfield) Newsgroups: comp.lang.modula2,comp.lang.misc,comp.lang.c,comp.lang.pascal Subject: Re: Modula2's godawful IO. Message-ID: <6366@watdragon.waterloo.edu> Date: 13 Apr 88 13:50:24 GMT References: <764@ndsuvax.UUCP> <535@m10ux.UUCP> <96@lzaz.ATT.COM> <547@m10ux.UUCP> Sender: daemon@watdragon.waterloo.edu Reply-To: gjditchfield@violet.waterloo.edu (Glen Ditchfield) Organization: U. of Waterloo, Ontario Lines: 24