C++之字符串string

发布时间 2023-10-11 07:02:54作者: 达可奈特

记录cpp相关的字符串操作

#include <string>

以下是string相关的常见操作

  1. 反转
  2. 字符串相加
  3. 转为int型:利用stoi将字符串转为整型(https://www.geeksforgeeks.org/stdstoi-function-in-cpp/)
  • 同float
  1. C++ 字符串split
    int idx = str.find(' ') 如有多个字符该如何,返回第一次出现的位置吗
    str.substr(idx, length) 起始坐标+子串长度

字符子串
用到的函数

#include <string>
idx = str.find_last_of
str.substr(strIdx, length)

C++字符串Split: https://java2blog.com/split-string-space-cpp/

  • int/float转为string: std::to_string()