0

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.

Sarat
  • 3
  • 3
  • 3
    The error is from your linker not the application itself. Not sure about MacOS but on Linux an errno value of 21 corresponds to `EISDIR`. That implies your intended output file `/Users/sarath/Documents/code` already exists but is a directory. – G.M. Mar 25 '20 at 11:33
  • 1
    Rename your "code.cpp" file so that the part before ".cpp" is not already the name of something in the Documents folder. – molbdnilo Mar 25 '20 at 11:44
  • ThankYou very much , it is because of duplicate file and directory names. – Sarat Mar 25 '20 at 16:11

0 Answers0