One should keep to standards wherever practical. Thus, don't write
void main
which has never been valid C or C++, but instead write
int main
With that, your code can compile with e.g. g++
(with usual compiler options).
Given the void main
I suspect a Windows environment. And anyway, in order to support use of your program in a Windows environment, you should not use the main
arguments in Windows. They work in *nix because they were designed in and for that environment; they don't in general work in Windows, because by default (by very strong convention) they're encoded as Windows ANSI, which means they cannot encode filenames with characters outside the user's current locale.
So for Windows you better use the GetCommandLine
API function and its sister parsing function. For portability this should better be encapsulated in some command line arguments module. Then you need to deal with the interesting problem of using wchar_t
in Windows and char
in *nix…
Anyway, I'm not sure of corresponding *nix API, or even if there is one, but google it. In the worst case, for *nix you can always initialize a command line arguments module from main
. The ugliness for *nix stems directly from the need to support portability with C++'s most non-portable, OS-specific construct, namely standard main
.
int main
overvoid main
. However, the other commentary leaves me … bemused. Which system other than Windows has a problem with the standard C++ convention formain()
? I'm not aware of one, so castigating the standard convention as 'non-portable' and 'OS-specific' seems OTT. – Leung