Here's a way to do the first option. (Using OldGuy2's tmp technique to avoid the exception handling ... and testing that the files actually open ...)
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
struct Data
{
int i, j;
double Iij, ton, toff;
};
istream& operator >> (istream &is, Data &s)
{
return is >> s.i >> s.j >> s.Iij >> s.ton >> s.toff;
}
ostream& operator << (ostream &os, const Data &s)
{
return os << s.i << ' ' << s.j << ' '
<< s.Iij << ' ' << s.ton << ' ' << s.toff;
}
int main()
{
const char *input_files[] = {
"a.txt", "b.txt", "c.txt", NULL
};
vector<Data> data;
for (int i = 0; input_files[i]; i++)
{
ifstream ifs(input_files[i]);
if (!ifs)
{
cerr << "Error opening file: " << input_files[i] << '\n';
return 1;
}
Data tmp;
while (ifs >> tmp)
{
data.push_back(tmp);
}
}
for (const auto& d : data)
{
cout << d << '\n';
}
}