Get a file name from a path

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

    std::string getfilename(std::string path)
    {
        path = path.substr(path.find_last_of("/\\") + 1);
        size_t dot_i = path.find_last_of('.');
        return path.substr(0, dot_i);
    }
    

提交回复
热议问题