Hamburgpear wrote in message <43********@newsgate.hku.hk>...
Thanks John,
Actually I have the following problems when I using ifstream.
I tried to count the total number of data from a txt file using while loop.
The terminating condition is (xxx.peek() != EOF).
Then, I allocate appropiate size to an array for data storage.
When I try to start a new loop to read data from the txt file, it will not
work becasue the return value of xxx.peek() is always equal to -1. It
doesn't work even I use a for-loop to read data with the same object. It
seems that the object "xxx" is still at the position of EOF. Am I right?
So, how to fix this problem? Now, I need to use another object for reading
and storing data. does it make sense to do it this way?
Thanks
HP
Please don't top-post.
You don't need to hit the EOF to get the size of the file:
std::ifstream Ping("BR4.png", std::ios_base::binary );
if(!Ping){
std::cout<<"\n ifstream FAILED"<<std::endl;
}
std::cout<<" ifstream Ping.tellg() = "<<Ping.tellg()<<std::endl;
Ping.seekg(0, std::ios::end);
std::cout<<" Ping.seekg(0, ios::end) Ping.tellg() =
"<<Ping.tellg()<<std::endl;
Ping.seekg(0, std::ios::beg);
std::cout<<" Ping.seekg(0, ios::beg) Ping.tellg() =
"<<Ping.tellg()<<std::endl;
Ping.close();
// --- output ---
// ifstream Ping.tellg() = 0
// Ping.seekg(0, ios::end) Ping.tellg() = 4499
// Ping.seekg(0, ios::beg) Ping.tellg() = 0
Did that help?
--
Bob R
POVrookie