Run a C++ Project main() multiple times in Visual Studio? -
i have visual studio c++ project. if want run once, can manually input arguments of
int main(int argc, char** argv)
into debugging options
, click debug.
however now, wish run multiple times different parameters in 1 go. e.g. wish run this:
for(i=0; i<10; i++) { main(i); }
how may visual studio?
i don't believe it's technically legal (per standard) call main
. if were, you'd passing wrong parameters (argc == 1
, argv == ${deity}_only_knows
).
this problem perhaps solve cmd script. make sure program compiled, run like:
@echo off cd \path\to\debug\dir rem bit can complex cmd.exe allows: /l %%a in (0,1,50) ( /l %%b in (0,1,10) ( echo data.txt result.txt %%a %%b ) )
this run command (echo
in case can see working should replace actual executable name, , modify cd command select proper directory) 561 times (51 x 11) first 2 arguments fixed , last 2 running 0-50 , 0-10, output of finishes:
: : : : : : : : : : data.txt result.txt 49 7 data.txt result.txt 49 8 data.txt result.txt 49 9 data.txt result.txt 49 10 data.txt result.txt 50 0 data.txt result.txt 50 1 data.txt result.txt 50 2 data.txt result.txt 50 3 data.txt result.txt 50 4 data.txt result.txt 50 5 data.txt result.txt 50 6 data.txt result.txt 50 7 data.txt result.txt 50 8 data.txt result.txt 50 9 data.txt result.txt 50 10
there may way vs automatically part of build/run sequence i'm not aware of (and tend opt simplest solutions of time).
you could, of course, refactor code rename main
else have filter main
follows:
int main (int argc, char *argv[]) { // normally: return worker (argc, argv); // or debugging: // int stat = 0; // (int = 0; < 10; i++) { // // construct argv-lookalike based on i. // stat = worker (myargc, myargv); // if (stat != 0) break; // } // return stat;
however, construction of argv-array not trivial since have follow same rules laid out in standard, argc
, argv
must agree, argv
must array of character pointers (one more indicated argc
) each argument c-style string, argv[0]
must represent program name, argv[argc]
must null, , on.
it's easiest use cmd
script solution , let startup code take care of argument preparation you.
Comments
Post a Comment