保留某个字符后的子字符串
string data = "hello world!";
string subdata = data.substr(data.find_last_of(' ') + 1); //world!
保留某一位后的子字符串
string data = "hello world!";
string subdata = data.erase(0, 6); //world!
保留从m位到长度为n的子字符串
string data = "hello world!";
string subdata = data.substr(6, 5); //world
获取不带路径的文件名
#include <iostream>
#include <string>
using namespace std;
string path = "E:\\test\\1.txt";
string::size_type iPos = path.find_last_of('\\')+1;
string filename = path.substr(iPos, path.length() - iPos); //1.txt
获取不带后缀的文件名
string name = filename.substr(0, filename.rfind(".")); //1
获取后缀名
string suffix_str = filename.substr(filename.find_last_of(".") + 1); //txt