//分割字符串
void Stringsplit(string str, const const char split, vector<string>& res)
{
istringstream iss(str); // 输入流
string token; // 接收缓冲区
while (getline(iss, token, split)) // 以split为分隔符
{
res.push_back(token);
}
}
// 合并字符串
string mergeString(vector<string> sStringTmp)
{
string newScpe;
for (int i = 0; i < sStingTmp.size(); i++)
{
string s1 = sStringTmp[i];
newScpe = newScpe + s1;
if (i != sStringTmp.size() - 1)
{
newScpe = newScpe + "\\";
}
}
return newScpe;
}
void main()
{
string sTmp ="E:\\das\\1";
vector<string> vecTmp;
Stringsplit(sTmp,'\\',vecTmp);
string slastString = mergeString(vecTmp);
}
C++ 字符串分割 字符串合并
最新推荐文章于 2024-07-25 09:47:19 发布