C++ STD库使用

一、基本概念

1、inline函数

二、容器

1、std::pair和std::map

2、std::set


字符串处理

三、 1、字符串分割

#include <iostream>
#include <string>
#include <vector>

std::vector<std::string> vStringSplit(const  std::string& s, const std::string& delim=",")
{
    std::vector<std::string> elems;
    size_t pos = 0;
    size_t len = s.length();
    size_t delim_len = delim.length();
    if (delim_len == 0) return elems;
    while (pos < len)
    {
        int find_pos = s.find(delim, pos);
        if (find_pos < 0)
        {
            elems.push_back(s.substr(pos, len - pos));
            break;
        }
        elems.push_back(s.substr(pos, find_pos - pos));
        pos = find_pos + delim_len;
    }
    return elems;
}

2、数组字符串互转

CSDN

3、find_first_of/find_last_of

简单的模式匹配。函数最容易出错的地方是和find函数搞混。它最大的区别就是如果在一个字符串str1中查找另一个字符串str2,如果str1中含有str2中的任何字符,则就会查找成功,而find则不同;
同样find_last_of查找最后出现的一个字符

//对比QT中的QString函数
QString::indexOf("abc")
QString::mid(pos+1,len)
posted @ 2025-10-24 17:19  wuya178  阅读(5)  评论(0)    收藏  举报