美文网首页
C++字符串

C++字符串

作者: 格调七弦 | 来源:发表于2016-03-30 15:35 被阅读38次

find:

find函数有以下四种重载版本:

size_t find (const string& str, size_t pos = 0) const noexcept;

//查找string对象

size_t find (const char* s, size_t pos = 0) const;

//查找char* 字符串

size_t find (const char* s, size_t pos, size_type n) const;

//从pos开始查找n位

size_t find (char c, size_t pos = 0) const noexcept;

//查找字符

参数说明:

str/s/c:要寻找的字符/字符串。

pos:目标串查找的开始位置。

函数返回序列第一次出现的位置,如果没有找到则返回string::npos。

split()

C++ STL,string 无该函数,可利用string.find(),string.substr()实现。

substr()

basic_string substr(size_type _Off = 0,size_type _Count = npos) const;

参数

_Off:所需的子字符串的起始位置。字符串中第一个字符的索引为 0,默认值为0.

_Count:复制的字符数目

返回值:一个子字符串,从其指定的位置开始

若size_type _Count超出目标串pos到结束的长度,则返回pos到目标串结束。

相关文章

网友评论

      本文标题:C++字符串

      本文链接:https://www.haomeiwen.com/subject/wvxelttx.html