Pls help taking input from text file and and want to make output into a file

#ifndef ONLINE_JUDGE
freopen(“C:/Users/A/Desktop/xyz.txt”,“r”,stdin);
freopen(“C:/Users/A/Desktop/OUTPUT.txt”,“w”,stdout);
#endif

I want to open an input file xyz.txt from desktop and then want to make an output file OUTPUT.txt to desktop please help me for this the above code is not giving the output into the file.

Can you post the whole code for reference? Everything seems to be right here.

And also format the code.

Works in my system.
You sure you dont have any problem elsewhere ?

You’re supposed to use freopen() inside main().

Dude its a facebook cup code, the contest is live! take your logic away!

2 Likes

I’m sorry I asked the code man :no_mouth:. You must’ve said it’s an on going contest. Keep your code safe.

1 Like

sorry for that

its okay that was my fault

Anyways, try using freopen() inside main. Or redirect the streams while running your code like this.

$ ./a.out < input.txt > output.txt
No modifications need to be done in your code if you’re using the second method.

1 Like