What is a cross-platform way to get the current directory?

前端 未结 3 1462
孤街浪徒
孤街浪徒 2020-12-05 23:55

I need a cross-platform way to get the current working directory (yes, getcwd does what I want). I thought this might do the trick:

#ifdef _WIN32
    #includ         


        
3条回答
  •  忘掉有多难
    2020-12-06 00:39

    If it is no problem for you to include, use boost filesystem for convenient cross-platform filesystem operations.

    boost::filesystem::path full_path( boost::filesystem::current_path() );
    

    Here is an example.

    EDIT: as pointed out by Roi Danton in the comments, filesystem became part of the ISO C++ in C++17, so boost is not needed anymore:

    std::filesystem::current_path();
    

提交回复
热议问题