This is a simple code snippet that prints out bytes from a file.
void printBytes(string path) {
ifstream input(path, std::ios::in | std::ios::binary);
vector<uint8_t> bytes((istreambuf_iterator<char>(input)), (istreambuf_iterator<char>()));
input.close();
for (uint8_t b: bytes) {
cout << hex << setw(2) << setfill('0') << static_cast<int>(b) << endl;
}
}
Why do the arguments passed into the constructor for the vector need to be wrapped in parenthesis? When I don't include the parenthesis I get a compile error. However, they seem redundant to me and I do not understand why they are required.
I thought there exists an implicit separation between function arguments and something like this should work.
vector<uint8_t> bytes(istreambuf_iterator<char>(input), istreambuf_iterator<char>());