The easiest way would be to use a std::vector to hold your data. You can keep on inserting data, and it will keep on resizing its internal array to hold it, so long as the system has sufficient memory to store it.
The following code shows how to read an aribrary number of strings into a vector. You might want to store a different kind of object in the vector, and create them by reading into a string and then parsing the string.
Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
int main() {
std::ifstream in("compile.cpp");
std::string line;
std::vector<std::string> lines;
// read all the lines in the file
while (std::getline(in, line)) {
// for every line in the file, put it at the back of the vector
lines.push_back(line);
}
// output all the lines we read before
for (int i = 0; i < lines.size(); ++i) {
std::cout << lines[i] << '\n';
}
return 0;
}