I use the NetBeans to program C++ , I want to get the current absolute path of the executable file
(~/NetBeansWorkSpace/project_1/dist/Debug/GNU-Linux-x86/executableFileName)
so I use
1, system("pwd")
2,getcwd(buffer,bufferSize)
then click the run button but they all get the wrong path: ~/NetBeansWorkSpace/project_1
Here is the surprise , I run the bash
cd ~/NetBeansWorkSpace/project_1/dist/Debug/GNU-Linux-x86/executableFileName
./executableFileName
I get the right path .
It’s WHY ???
As everyone else has stated, NetBeans is setting the working directory before running your application. If you want to get the working directory of the executable, I believe that the following should work.