how to test as i use visual studio

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

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;
}
3 Likes

Never Mind I found the solution myslef.
1> After you have successfully Build and Run the code at the Top Bar where you see Debug its a drop down menu, select Release there and then Build.
2> Below in the output where its usually shows you compiling details and if the Build was successful or failed there it will give you the path of the .exe (ProjectName.exe) , which is nothing but your executable code, your console C/C++ application that you just built.
3> Now go to that path , right where that .exe file is and create your in.txt input file there.
4> Now go to CMD and go to that path (comment ,if you dont know how) and then type that .exe filename first, like program.exe <in.txt> out.txt
5> And you are done. Go back and you will find your out.txt file has been created. GOOD LUCK

No one knows the answer ?? @admin pls help!!

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.