views:

38

answers:

1

Hi,

I am going to take part in a coding contest my University is organizining next week. I am only allowed to use C or C++ and I would prefer to use the latter one using Visual Studio 2010. For every task there is a text input provided as plaintext to stdin, for example:

200 100 10
2 11

I need a tool which would assist me with running my code with some pre-defined text file as stdin input.

On a unix-based system I would just use something like:

gcc mycode.cpp
./mycode.o <test1.in >result1.out
diff result1.out test1.out

Is there any way to reach this in Visual Studio 2010.

Or maybe one could recommend a nice C++ IDE with rich debugging functions which would have something like this "out of the box"?

With best regards, Alexander.

+1  A: 

You can do essentially the same thing with the Visual Studio compiler and the Windows command line:

cl /EHsc mycode.cpp
mycode.exe <test1.in >result1.out
fc result1.out test1.out

Though you might want a better diff tool than fc.

You can also code up your code so the routine that does the real work is called with stream handles (or some other mechanism to get and put the data) and have a test build feed the data through files that it opens instead of stdin and stdout. When your testing is done, the real program simply calls that routine with the stdin and stdout handles.

There are unit test frameworks for C++ that might help you with that, but getting one of them installed and integrated in might be more trouble than just writing your own simple test jig.

Michael Burr
Thank you a lot, that works fine with command line and fc is fully ok for my needs.The only question I have now is then: can I somehow make Visual Studio to start my debug session automatically with some parameters, like "<test1.in"?
Alexander
@Alexander: in the VS 2010 C++ project properties go to the "Debugging/Command Arguments" setting and put in "<test1.in" (without the quotes).
Michael Burr