#include #include <dirent.h> int main() { char buff[256] = {0}; getcwd(buff, 256); std::cout << buff << std::endl; return 0; }
The value of argc shall be nonnegative. argv[argc] shall be a null pointer.
If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-de?ned values by the host environment prior to program startup. The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. If the host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are received in lowercase.
If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment. If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters.
The parameters argc and argv and the strings pointed to by the argv array shall be modi?able by the program, and retain their last-stored values between program startup and program termination.
prompt>cat test.c #include <stdio.h> int main(int argc, char** argv) { puts(argv[0]); return 0; } prompt>mkdir sub prompt>gcc test.c -o sub/test.exe prompt>sub/test.exe sub/test.exe prompt>export PATH=sub:$PATH prompt>test.exe test.exe prompt>
By convention, argc is greater than zero; the first s argument (in argv[0]) is the command name itself.
#include #include <cstring> #include <cstdlib> #include <libgen.h> int main(int, char** argv) { std::string path(argv[0]); char* tmpCpy = strdup(path.c_str()); std::cout << "Dirname of " << path << " => " << dirname(tmpCpy) << std::endl; free(tmpCpy); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionconnais-tu une fonction équivalente au ExtractFilePath()