D
Dr. Len
Hi all!
Given that I have a binary file which contains 4-byte integer values
in sequence and I know in advance how many there are, does the C++
standard have any algorithm or like method to read them into a
std::vector container with a single command? Right now I'm using a
temporary variable and push_back(), but this is bit clumsy way IMO:
int tmp;
std::vector<int> someVector;
std::ifstream in("somefile", std::ios_base::in |
std::ios_base::binary);
for(int i = 0; i < count; i++)
{
in.read((char*)&tmp, 4);
someVector.push_back(tmp);
}
Given that I have a binary file which contains 4-byte integer values
in sequence and I know in advance how many there are, does the C++
standard have any algorithm or like method to read them into a
std::vector container with a single command? Right now I'm using a
temporary variable and push_back(), but this is bit clumsy way IMO:
int tmp;
std::vector<int> someVector;
std::ifstream in("somefile", std::ios_base::in |
std::ios_base::binary);
for(int i = 0; i < count; i++)
{
in.read((char*)&tmp, 4);
someVector.push_back(tmp);
}