mardi 13 septembre 2016

C++ get current file directory in Linux

This question is many time asked and I referred all , but I need bit different.

I am using macbook -> Clion (IDE) for C++ My program file location /Users/Kandarp/ClionProjects/SimulationParser/main.cpp

When I use following function for get current directory it gives different file (I think actual path where file is compiled and execute)

string ExePath() {
char cwd[1024];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
    fprintf(stdout, "Current working dir: %s\n", cwd);
    return cwd;
} else {
    perror("getcwd() error");
    return 0;
}}

it gives following answer: /Users/Kandarp/Library/Caches/CLion2016.2/cmake/generated/SimulationParser-50b8dc0e/50b8dc0e/Debug

But I need path where my .cpp file reside.What I am doing wrong ? Please help

Aucun commentaire:

Enregistrer un commentaire