Well , i was thinking to automate process of testing manually our codes with testdata just like it would be done in compilers of servers. I can easily get runtime required by my code to execute (via time library) but problem i face is , i am using standard i/o (cin,cout) and i have 10 test data files as 1.in,1.out,2.in,2.out ... 10.in,10.out and i was thinking to automatically test my code (from input files 1.in,2.in ...) and compare them with test outputs (1.out,2.out ...) and see if they correct .
But i have no idea on how to supply input from a file to code which takes input via cin and compare its output again with another file ???
I don't think there's a generic C++ solution to you problem. Unless you modify your code so it can (optionally) read the i/p from a file rather than cin.
Also, have you come across diff tools, like diff.exe?
And how complex/thorough a solution are you looking for. Or would something basic/pragmatic be good for you? Is this a educational project? Or??
Andy
PS @pogrady
I don't get the point of posting code which is that defective?
@pogrady i think you got it wrong , i have some text files to compare but main thing i want is to is call a .cpp program , execute it by providing some inputs in another file and save output by programme in a txt file .
@andywestken , i dont wish to modify my code , no i am unaware about diff.exe ?
I am not looking for a very complex solution , it should just be able to execute a cpp program (which uses cin) supplying inputs via txt file then getting o/p by code (code uses cout) and save it into another txt file . Comparing part i can do myself . Everything is almost same as online contest judge !
Yep , something basic would certainly do for me - i will be using it as sort of checking my programs with test data given in coding contest .
A quick solution for Windows would be to use a batch file. In its simplest form, it would be
1 2 3 4 5
@echo off
rem run tests
myapp.exe < 1.in > 1.out
myapp.exe < 2.in > 2.out
myapp.exe < 3.in > 3.out
Note that this batch file assumes that all the files (inc. exe and test i/p and o/p) are in the same folder, and that you open a command prompt and cd to this folder and run the batch file from there. As > is being used, the .out files will be overwritten on each run.
(I would prob, at least, put the inputs in one subfolder and write the results into another, to avoid getting the files muddled).
If you're using Linux, you should be able to do the same kind of thing with a shell script.