What is the alternative to getopt function on Windows c++?

Jones Jardel Poersch picture Jones Jardel Poersch · May 12, 2015 · Viewed 21k times · Source

The code below I'm using Posix C:

while ((opt = getopt(argc, argv, "a:p:h")) != -1)

How can I port this code to Windows C++ using an alternative function?

Thanks

Answer

Joey picture Joey · Jun 17, 2017

Microsoft has provided a nice implementation (as well as some other helpers) inside the open source IoTivity project here you could possibly re-use (pending any licensing requirements you may have):

Take a look at the "src" and "include" directories here for "getopt.h/.c".

https://github.com/iotivity/iotivity/tree/master/resource/c_common/windows