我想在一個給定的文件輸出讀取字符的十六進制字符數。當我對一個文本文件運行它時,它或多或少是準確的,但與其他任何東西似乎都是一樣的。 IE:大約700MB的* .mp4文件將在12K出現。我在這裏錯過了什麼?(C++)noob - 我的代碼有什麼問題?
#include <fstream>
#include <iostream>
using namespace std ;
int main()
{
char letter ;
int i ;
cout << "Input the filename:" << endl;
string stringinput;
cin >> stringinput;
ifstream file(stringinput.c_str()) ;
if(! file)
{
cout << "Error opening input file, " << (stringinput) << ". Check file path and try again." << endl ;
return -1 ;
}
else
for(i = 0; ! file.eof() ; i++)
{
file.get(letter) ;
//cout << hex << (int) letter;
}
cout << endl;
float k = 1024, m = 1048576;
file.close();
if(i < 1024)
{
cout << "Total: " << dec << i << endl;
}
else if(i < m)
{
cout << "Total: " << dec << (i/k) << "K" << endl;
}
else
{
cout << "Total: " << dec << (i/m) << "M" << endl;
}
return 0 ;
}
你打開在文本模式下的文件......別人可以闡述。 :) –