0
#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;

int main() {
    FILE* fd;
    fd = freopen("1.txt", "w", stdin);
    int a = 1;
    cin >> a;
    cout << a;
    fclose(fd);
    cin >> a;
    cout << a;
    return 0;
}

I use freopen to connect stdin and 1.txt. Then, i want to close 1.txt and later work with regular stdin, but is isn't works. What i have to do? (In 1.txt only one number - 1, program at the end puts in console - 11; i want it to put 1, then ask me for a number)

  • Related: https://stackoverflow.com/q/1908687/10871073 That's about `stdout` and in C but I think much of what is said there is applicable here. – Adrian Mole Feb 15 '23 at 10:33

0 Answers0