Problem with ifstream

A

Alexandros

I do something like this:

ifstream file(argv[1]); if(!file) //...
file.read(buffer,BUFFSIZE);
while(!file.eof())
{
for(int i=0; i<BUFFSIZE; i++)
// ...

file.read(buffer,BUFFSIZE);
}
int nlastread=file.gcount();
for(int i=0; i<nlastread; i++)
// ...

And then things like these don't work;

file.seekg(0); // file.tellg() is -1
file.seekg(20) // file.tellg() is still -1
file.close(); file.open(argv[1]) // Can't open: !file is true.
the only way to do it I've found is:

ofstream file2(argv[1]);

but I'm not very keen on that solution.

What do you think?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top