Not reading in entire file.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 24
Reputation: SquirrelProdigy is an unknown quantity at this point 
Solved Threads: 0
SquirrelProdigy's Avatar
SquirrelProdigy SquirrelProdigy is offline Offline
Newbie Poster

Not reading in entire file.

 
0
  #1
Nov 22nd, 2004
I just can't figure out why this program isn't reading in the entire file. It will only read in the second line, nothing else.

Here are my read and write functions:

bool Write(string Text,string FileName){
fstream Write;
Write.open(FileName.c_str(),ios::out|ios::app);
if(!Write){
cout<<"Error in opening file";
return 0;
}
Write<<Text;
Write.close();
return 1;
}

void Read(string FileName){
char buffer[300];
fstream Read;
Read.open(FileName.c_str(),ios::in);
Read.seekg(0,ios::beg);
while(!Read.eof()) Read.getline(buffer,300);
cout<<buffer;
Read.close();
}

Thanks for your time,
Squirrel Prodigy
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Not reading in entire file.

 
0
  #2
Nov 22nd, 2004
You have:
while(!Read.eof()) Read.getline(buffer,300);
cout<<buffer;

Maybe you meant:
while(!Read.eof())
{
Read.getline(buffer,300);
cout<<buffer;
}
?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 24
Reputation: SquirrelProdigy is an unknown quantity at this point 
Solved Threads: 0
SquirrelProdigy's Avatar
SquirrelProdigy SquirrelProdigy is offline Offline
Newbie Poster

Re: Not reading in entire file.

 
0
  #3
Nov 23rd, 2004
Thanks a bunch, that fixed it. I didn't realize that it was replacing buffers contents everytime it read in a second line.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC