1

I used following code to read a binary file and store its content in a vector. But the vector.size() printed is smaller than the file size. What's the problem here?

#include <iostream>
#include <iterator>
#include <fstream>
#include <vector>
using namespace std;

int main(){
    ifstream is(myfile,ios::binary);
    istream_iterator<unsigned char> start(is),end;
    vector<unsigned char> v(start,end);
    cout << v.size() << endl;
    return 0;
}

Output: 7805148

File size: 7840016

Vishaal Shankar
  • 1,648
  • 14
  • 26
Mindong
  • 89
  • 9

0 Answers0