C++アプリケーションが存在するパスの取得


C++でウィジェットを書くと、環境が簡単なので、システムAPIを呼び出したくないので、以下の方法で実現します.
    //argv[0]            
    string filename(argv[0]);
    //    Windows              \  /
    size_t found = filename.find_last_of("\\");
    size_t found2 = filename.find_last_of("/");
    //         
    found = (found >= found2 ? found : found2);
    //           
    string cwd = filename.substr(0, found);
//          ,             ,       ,          
char filepath[256];
getcwd(filepath, 256);