Get a file name from a path

前端 未结 21 1574
面向向阳花
面向向阳花 2020-11-30 23:55

What is the simplest way to get the file name that from a path?

string filename = \"C:\\\\MyDirectory\\\\MyFile.bat\"

In this example, I s

21条回答
  •  北海茫月
    2020-12-01 00:33

    If you can use boost,

    #include 
    path p("C:\\MyDirectory\\MyFile.bat");
    string basename = p.filename().string();
    //or 
    //string basename = path("C:\\MyDirectory\\MyFile.bat").filename().string();
    

    This is all.

    I recommend you to use boost library. Boost gives you a lot of conveniences when you work with C++. It supports almost all platforms. If you use Ubuntu, you can install boost library by only one line sudo apt-get install libboost-all-dev (ref. How to Install boost on Ubuntu?)

提交回复
热议问题