VSB
VSB

Reputation: 242

seekg does not work after while(file.good()) {....}

I'm fairly perturbed that the below does not appear to work.

while(myfile.good())
{   
    myfile.get(holdc);      
    ....................
}

//does not work 
myfile.seekg(0);
myfile.read(buffer,5);
sentence.push_back(buffer);
cout << buffer<<endl;
delete[] buffer;

I have tried myfile.close, etc., even creating a new ifstream myfile2; to reload the file. Nothing works. It's as if this seekg thing is universal or something, and works only once per program.

Upvotes: 0

Views: 228

Answers (1)

VSB
VSB

Reputation: 242

it appears, right after

    while(myfile.good())
 {   
    myfile.get(holdc);      
    ....................
}

I need to do

myfile.clear();

However, I still need to know how to go ahead through the new line and read form file. After the first line ends I get random symbols. Anyone?

edit**

What happened was I used a dynamic array char buffer, which needs to be closed with:

buffer[i] = 0;

Upvotes: 0

Related Questions