From: adalee AT sendit DOT sendit DOT nodak DOT edu (Adam W Lee) Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem with fstreams... Date: 24 Aug 1997 19:30:18 GMT Organization: SENDIT - North Dakota's Educational Network Lines: 47 Message-ID: <5tq24a$b6$1@news.sendit.nodak.edu> References: <5tps7b$rpo$1 AT news DOT sendit DOT nodak DOT edu> NNTP-Posting-Host: sendit-2.sendit.nodak.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Adam W Lee (adalee AT sendit DOT sendit DOT nodak DOT edu) wrote: : I'm trying to write a program to read a file and write it to another file : in C++, but my program quits like halfway through the file with a read : error or something to that effect... Here's some pseudo-code. OK, now the plot thickens :) This program works perfectly under BSDi/OS... Here's the actual code: #include int main(int argc, char *argv[]) { char temp[1025]; if(argc<3) { cout << "Usage: " << argv[0] << " " << endl; return 1; } ifstream in(argv[1]); if(in.fail()) { cout << "Error opening " << argv[1] << endl; return 2; } ofstream out(argv[2]); if(out.fail()) { cout << "Error opening " << argv[2] << endl; return 3; } while (!in.eof()&&!in.fail()&&!out.fail()) { in.read(&temp,1024); out.write(&temp,in.gcount()); } out.flush(); if(in.eof()) cout << "End of file reached." << endl; if(in.fail()&&!in.eof()) cout << "Error reading " << argv[1] << "." << endl; if(out.fail()) cout << "Error writing " << argv[2] << "." << endl; in.close(); out.close(); return 0; }