Mail Archives: djgpp/1997/08/28/02:35:36
From: | adalee AT sendit DOT sendit DOT nodak DOT edu (Adam W Lee)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Problem with fstreams...
|
Date: | 24 Aug 1997 17:49:31 GMT
|
Organization: | SENDIT - North Dakota's Educational Network
|
Lines: | 44
|
Message-ID: | <5tps7b$rpo$1@news.sendit.nodak.edu>
|
NNTP-Posting-Host: | sendit-2.sendit.nodak.edu
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
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.
#include <fstream.h>
int main(void)
{
char temp;
ifstream in("infile");
ofstream out("outfile");
if (in.fail()||out.fail())
{
cout << "File error" << endl;
return 1;
}
while (!in.eof()&&!in.fail()&&!out.fail())
{
in >> temp;
out << temp;
}
in.close();
out.close();
cout << "Copying successful" << endl;
return 0;
}
I tried using in.get(temp) which worked better most of the time, or
in.read(char *temp,1024) and then out.write(temp,in.gcount()) but none of
these got the whole file... Any suggestions?
PS - If there are any dumb bugs or anything in this code please don't
suggest that as the problem because I just coded this online and probably
did something dumb :P
--
+--- -- -- - -
| [pHiXx/VorteX]
: phixx AT usa DOT net
:
.
- Raw text -