If you're using Windows, you could try GetModuleFileName( ).
Code:
#include <iostream>
#include <cstring>
#include <windows.h>
#define maxval( a, b ) ( (a) > (b) ? (a) : (b) )
int main( void ) {
char fileName[ MAX_PATH ];
int pathLength = GetModuleFileName( GetModuleHandle( NULL ), fileName, MAX_PATH );
if( !pathLength ) std::cout<<"Couldn't find path."<<std::endl;
else {
char *lastSlash = maxval( strrchr( fileName, '\\\' ), strrchr( fileName, '/' ) ) + 1;
*lastSlash = '\0';
std::cout<<"File path: "<<fileName<<std::endl;
}
}