Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!europa.asd.contel.com!gatech!hubcap!ncrcae!secola!jmartin From: jmartin@secola.Columbia.NCR.COM (John Martinez) Newsgroups: comp.lang.c++ Subject: Treating cin, cout like files (or vice versa) Message-ID: <365@secola.Columbia.NCR.COM> Date: 29 Jun 91 19:12:17 GMT Reply-To: jmartin@secola.Columbia.NCR.COM (John Martinez) Organization: NCR NPD Columbia Lines: 62 OK netters, here's my dumb question for the week: Environment: DOS 4.01, Borland C++ Reader's Digest Version: I want to write a sort of template for "pipe" style programs which take one input file, mess with it, and put the output to another file; the code should default to using cin and cout unless filenames are on the command-line. e.g. Both [all three] of these should do the same thing: cat filea | my_program > fileb works, but so does my_program filea fileb and maybe even [dare to dream :)] cat filea | my_program - fileb sounds simple, right? And it probably is, but I can't seem to get anything which seems like it might work to compile! :( I want to do something like: (yes, I know _this_ code is _way_ wrong...) ********** #include main (int argc, char *argv[]){ ifstream in_stuff; ofstream out_stuff; if (argc >=1) in_stuff = argv[1]; else in_stuff = cin; [ same sort of thing for out_stuff here....] [ code that uses in_stuff and out_stuff here and doesn't know or care if we are using files or cin/cout goes here ] }; - you get the picture. But none of the [>20] variations on this theme I've tried seem to work; I'm lost in a hopeless tangle of ostreams, ofstreams, ofstreams-withassigns,iostreams,ice_creams, etc.... !! :( :( :( anybody feeling generous and want to tell me the secret? I won't even complain if the answer comes along with an RTFM flame, although I must protest that I have been R'ing the FM, and if the information is in there, it's rather deeply buried. advTHANKSance, -(-- John the miffed coder send replies to jmartin@secola.Columbia.NCR.COM ....yes, upper/lower case in the address matters - very annoying :( :( p.s. If anyone asks, I'll post or mail the working template when I have one. -- John V.Martinez NCR Network Products Division jmartin@secola.Columbia.NCR.COM (803)739-7671 vplus:633-7671