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?

Closed due to the fact that off-topic participants Abyx , aleksandr barakin , Alexey Shimansky , MihailPw , αλεχολυτ 10 Jun '17 at 15:44 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Abyx, aleksandr barakin, Alexey Shimansky, MihailPw, αλεχολυτ
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Are you returning a link to a local object? - retorta
  • ....I beg your pardon. Corrected, the question is closed. And thank you :) - Range
  • @Range, for the sake of interest - return a constant link, and see what happens :) - isnullxbh
  • already tried ... ehh i) - Range

0