I'm aware that there are other ways to accomplish the read of data. But I am confused, why in this code does the size print as 0? file.txt
is a random text file with more than 4 characters.
#include <iostream>
#include <fstream>
#include <vector>
int main() {
std::ifstream ifs("file.txt");
std::vector<char> file_vec{};
file_vec.reserve(4);
ifs.read(file_vec.data(), 4);
std::cout << file_vec.size() << std::endl;
ifs.close();
}