freopen() not able to write to a file?

509 Views Asked by At

On MacOSX, I'm trying to read input from inp.txt and write output to outp.txt on Sublime. I'm redirecting stdout to outp.txt

#include<iostream>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("inp.txt", "r", stdin);
    // for writing output to output.txt
    freopen("outp.txt", "w", stdout);
    #endif
    int n;
    cin>>n;
    cout<<n+1;
}

Error is

ld: can't open output file for writing: /Users/sarath/Documents/code, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 2.9s with exit code 1]
[shell_cmd: g++ "/Users/sarath/Documents/code.cpp" -o "/Users/sarath/Documents/code" && "/Users/sarath/Documents/code"]
[dir: /Users/sarath/Documents]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

Why it is failing and please help ? ThankYou.

0

There are 0 best solutions below