#include <iostream>
int main(int argc, char** argv)
{
std::string file = "/home/download/test.png";
int pos = file.find_last_of(‘/‘);
std::string path(file.substr(0, pos));
std::string name(file.substr(pos + 1));
std::cout << "file path is: " << path << std::endl;
std::cout << "file name is: " << name << std::endl;
return 0;
}
file path is: /home/download
file name is: test.png
注: 使用std::string 的find_last_of
做字符串分割
注: 使用std::string 的substr
提取子字符串
原文:https://www.cnblogs.com/chrislzy/p/14942289.html