function freopen is not reading inputs

462 Views Asked by At

I'm trying to test freopen("inputs.txt","r",stdin); but it is not working.Here is my code below:

#include <iostream>

using namespace std;

int main() {

    freopen("inputs.txt","r",stdin);

    int n;
    cin >> n;

    cout << n << endl;

    return 0;
}

There is only one integer number in my input file and it is in the same directory.
Can anyone help?

1

There are 1 best solutions below

0
On

Sorry I had a problem with the file path.File path should be in full form like

freopen("Users/mahfuz/inputs.txt","r",stdin);

this worked for me.