TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK MASINGILL
from: CLIFF RHODES
date: 1997-05-27 23:07:00
subject: IO streams

--> Frank Masingill wrote to Cliff Rhodes <--
FM>void main(int argc, char *argv[])
// Ahem, int main(...)
FM>{
FM>    if(argc != 3)
FM>    {
FM>        cerr << "\nUse Arguments";
FM>        exit(1);
FM>    }
FM>    char ch;
FM>    ifstream infile; ofstream outfile;
FM>    infile.open(argv[1]);             // I know I should stick in
FM>    cerr outfile.open(argv[2]);            // on both of these
FM>    calls. while(infile.get(ch) != 0)
FM>    {
FM>            outfile.put(ch);
FM>    }
  return 0;
FM>}
Looks good to me! It could use some error checking to make sure files 
are opened as expected. Also, you could use fstream constructors to 
open your files instead of the open() member.
ifstream infile(argv[1]);  // Constructor opens file argv[1]
 
FM>If this is correct, my next project is to try to process each line
FM>in such a way that I can delete it ' i.e. NOT write the line to the
FM>destination text file.  Or else designate a block of lines to skip
FM>over.
You probably won't want to use the get() and put() members to do that.
FM>    Any comments will be appreciated.  The enormous array
FM>of choices in dealing with streams in C++ is a little
FM>confusing as I am doing it without having learned C very
FM>much.
Since C++ streams are different from C I/O, you aren't at too much of 
a handicap. Don't feel bad about it, streams are confusing to 
everybody since they are so flexible.
Cliff Rhodes
cliff.rhodes@juge.com
X CMPQwk 1.42 1692 X"Divide and rule." - Latin Proverb
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.