我用 读入一个文件ifstream
,我想写出cout
已经读过多少文件,以百分比为单位。
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
}
只有now = length
向我表明它是100%
,但每隔一次它就会失败并给我回来0
。我可以想象,答案很简单1*1
,但现在我找不到解决方案。我也尝试过铸造,也许是因为这就是问题所在,但当然没有。