What is the alternative to getopt function on Windows c++? -
this question has answer here:
the code below i'm using posix c:
while ((opt = getopt(argc, argv, "a:p:h")) != -1)
how can port code windows c++ using alternative function?
thanks
if had searched have found thread goes on compatibility libraries getopt, among other implementations, windows based systems.
getopt.h: compiling linux c-code in windows
on note, use va_arg, va_list, va_start, , va_end functions process arguments well.
/* va_arg example */ #include <stdio.h> /* printf */ #include <stdarg.h> /* va_list, va_start, va_arg, va_end */ int findmax (int n, ...) { int i,val,largest; va_list vl; va_start(vl,n); largest=va_arg(vl,int); (i=1;i<n;i++) { val=va_arg(vl,int); largest=(largest>val)?largest:val; } va_end(vl); return largest; } int main () { int m; m= findmax (7,702,422,631,834,892,104,772); printf ("the largest value is: %d\n",m); return 0; }
reference: http://www.cplusplus.com/reference/cstdarg/va_list/
Comments
Post a Comment