0

I need to take input from a file and store some values. Then I want to receive some queries from the user. So if I use freopen() to read from a file, then how can I switch back to keyboard or terminal input?

I used freopen("input.txt", "r", stdin);

  • Why do you need `freopen` to read from a file? Why not just `fopen` it and read from the `FILE*` handle returned therefrom? – Igor Tandetnik Dec 20 '20 at 04:15
  • Using `freopen` to make `std::cin` a file does seem to be a fashion on here lately, don't do it, just use `std::ifstream`, it's so much simpler – Alan Birtles Dec 20 '20 at 05:38

0 Answers0