Here there is such a piece of code:
std::ifstream& save_files(const std::string& n) { std::ofstream file(n); for (int i(0); i < 100; i++) file << -50 + rand() % 101 << std::endl; file.close(); return std::ifstream(n); } template <class T> std::vector<T>& inputfile(std::ifstream& f) { std::cout << f.get() << std::endl; // BUG std::istream_iterator<T> iter(f); std::vector<T> result(100); while (iter != std::istream_iterator<int>()) result.push_back(*iter++); return result; } int main() { std::vector<int> v = inputfile<int>(save_files("numbers.txt")); } For some reason, when returning from the save_files function, the link to the file is lost, respectively, no reading is performed. Tell me how to correctly return the link to the stream?