How to fill a binary vector C++?

Is a vector:
#include <vector>

using TData = vector<byte>;</byte></vector>


You need to fill it from a file:
#include <fstream>

//InPut DATA
 ifstream InputFileData;
 InputFileData.open(src_file_name, ios_base::binary);
 TData DataBuf;
 //HERE copies all data into buffer
 InputFileData.close();</fstream>


There is a solution:

#include <iterator>

InputFileData((std::istreambuf_iterator<byte>(InputFileData)), (std::istreambuf_iterator<byte>()));</byte></byte></iterator>


But all this beauty does not work, two mistakes:
1. A call to an object of a class type without appropriate operator() or conversion functions to pointer to the function. (Emphasizes InputFileData)
2. There are no instances of the constructor matching the argument list. (Emphasizes the first iterator)

PS
I see that is not correctly written iterators, but do not know how to fix, can anyone have ideas? Do I need to change a file stream ofstream, on istream?
July 2nd 19 at 16:39
1 answer
July 2nd 19 at 16:41
Solution
I do not understand what is happening. You try in your version of the "decision" to call a functor? Or the designer already designed object?
The first option does not support ifstream. The second language is generally impossible.

You need from the opened file to copy data to the buffer, right?
Well then why not use the function named copy?

std::copy(std::istreambuf_iterator<byte>(InputFileData), std::std::istreambuf_iterator<byte>(), std::back_inserter(DataBuf));</byte></byte>


Or do something even simpler and fill the vector when creating:

TData DataBuf(std::istreambuf_iterator<byte>(InputFileData), std::std::istreambuf_iterator<byte>());</byte></byte>

Find more questions by tags C++