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

Recommended Answers

All 2 Replies

You have:
while(!Read.eof()) Read.getline(buffer,300);
cout<<buffer;

Maybe you meant:
while(!Read.eof())
{
Read.getline(buffer,300);
cout<<buffer;
}
?

Thanks a bunch, that fixed it. I didn't realize that it was replacing buffers contents everytime it read in a second line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.