Sublime Forum

Input output file online judge

#1

Every time I run my c++ code I need to create input output text files in the same location,
Can we use a single input.txt and output.txt for multiple programs located in different locations .
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif

I created input output text files in Desktop and gave path of these in freopen but I got error.
I recently started learning c++ so I dont have any idea about syntax and what online judge do .

0 Likes

#2

Filenames as you have them there are relative to the current directory, whatever that happens to be. There’s no reason why you should’t be able to put an absolute path in place to make it always use the same file for everything. What error did you see, and what platform are you on?

1 Like

#3

I got it, at the same time I modify 2 programs which are at different locations.now, to give an input for a particular file, I need to switch to input file which is in same lacation.so is there any way that I can give input in a single input file which in in some remote location.
Thanks for reply by the way I discovered your channel recently and loving it : )

0 Likes

#4

As I said above, there’s no reason you can’t specify a full path:

freopen(“/home/tmartin/some/really/long/path/input.txt”, “r”, stdin);

If trying it doesn’t work for you, then the only way to determine why is to know what error message you got was, which will help explain what it was that didn’t work.

1 Like

#5

I’m really sorry. I gave the wrong path(recently switched to linux). It’s working fine thanks for the help…

1 Like