There was a need to rewrite the project on STL. In the old version there was such a read into the array int from a binary file:

 for (unsigned i = 0; i < n; i++) in.read(reinterpret_cast<char*> (&ia[i]), sizeof(int)); 

Tried to rewrite as follows:

 std::ifstream ifs(nameFile, std::ios::binary); std::istream_iterator<int> ii(ifs); std::copy(ii, std::istream_iterator<int>(), ia.begin()); 

Vector ia remains empty. Search in Google did not give any results, for some reason all the examples do not work. Please help me (ps memory for the vector is allocated).

    1 answer 1

    std::istream_iterator used for text input, since works by calling operator>> . For binary reading from file to vector, you need to use read , which you already had:

     ifs.read(reinterpret_cast<char*>(ia.data()), ia.size() * sizeof(int));