I read in a file with ifstream, and I want to write out with cout how much of the file already read, in percent.
long length = 0, now = 0;
int i = 0;
double d = 0;
file.seekg( 0, std::ios::end );
length = file.teelg();
file.seekg( 0, std::ios::beg );
while ( std::getline( file, buffer ) ) {
now = file.teelg;
i = now / length * 100;
d = now / length * 100;
std::cout << length << " " // working
<< now << " " // working
<< ( now / length * 100 ) << " " // not working = 0
<< i << " " // not working = 0
<< d; // not working = 0
}
Only if now = length shows me that it’s 100%, but every other time it fails and gives me back 0.
I can imagine, that the answer is simple as the 1*1, but now I can’t find the solution. I also tried with casting, maybe because of that’s the problem, but of course nothing.
Unless one of the operands is a
floatordouble,/does integer division and discards the remainder.Write it like this: