Get a file name from a path

前端 未结 21 1624
面向向阳花
面向向阳花 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:23

    The boost filesystem library is also available as the experimental/filesystem library and was merged into ISO C++ for C++17. You can use it like this:

    #include 
    #include 
    
    namespace fs = std::experimental::filesystem;
    
    int main () {
        std::cout << fs::path("/foo/bar.txt").filename() << '\n'
    }
    

    Output:

    "bar.txt"
    

    It also works for std::string objects.

提交回复
热议问题