How do I initialize
std::vector<std::ifstream> from an existing std::vector<std::string> which are the names of the files that are intended to open?
Without an initialization of vector, I can do it using
std::vector<std::string> input_file_names;
// Populate the vector with names of files that needs to open.
// ...
std::vector<std::ifstream> input_files_;
for (auto const & input_file_name : input_file_names) {
input_files_.emplace_back(input_file_name);
}
In c++11, the
std::ifstreamconstructor will take astd::stringas a parameter. String that together with thestd::vectorcopy constructor, and this should work: