I am trying to change the current working directory to the path of the executable, using chdir()
in the following manner:
#include <iostream>
#include <string>
using namespace std;
int main(int argc,char *argv[]) {
if(chdir(argv[0]) == 0) printf("In %s\n", argv[0]);
else printf("Failed to change directory\n");
}
The output is:
Failed to change directory
Why doesn't chdir
work with argv[0]
? Other solutions for this issue would also be accepted.