how to test my c programs from command line as described here http://www.codechef.com/wiki/faq#How_should_I_test_my_program
I don’t see a way to do that as i am using visual studio. I want to test ,my program using <in.txt> as input and get an output on out.txt
No one knows the answer ?? @admin pls help!!
Place the file “in.txt” in your projects folder where your source file (.cpp) exists
Just add these two lines in your code, at the start of your main function.
After you run the program, a file with he name “out.txt” will be created.
What freopen() does is , it redirects the streams to files
#include<cstdio>
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
// your code from here
return 0;
}
2 Likes
I was looking for how to do it from command line , but anyways this is another good way to do it. I did found how to do it from cmd , below you will find my answer.