As you state in comments:
"... but for my ftp program I need to get the list of .txt
, .pdf
, etc. files, which are located at the same path as the .cpp
file."
You should have a kind of resource directory defined, that is created when your application is installed, and where your .txt
, .pdf
, etc. files will be copied by the installation process.
This way implies you have an installation process (which could be the simplest form, by just creating and extracting a .zip
archive), that bundles the executable .exe
file along these resource files, to be installed on the target machine. Usually, you won't include the source files there.
It's actually a bad idea, to refer to the location of your source .cpp
file in this case, since the finally installed program usually doesn't have a notion of the source it was compiled from. Also the program may be installed on a machine with a different environment (especially development environment) from yours.
A better entry point for a generic installation path, is to refer relative to the path that's given you with the argv[0]
argument of your main()
program entry. It provides you with the full path of your installed executable file.
For the rest, use the operations available from e.g. the boost::filesystem
library to manipulate path and file names in a portable way, as mentioned in comments.