C++ 关于字符串总结(持续更新)

时间:2023-03-09 15:07:34
C++ 关于字符串总结(持续更新)

1.find_first_of

size_type find_first_of( const basic_string &str, size_type index = 0 ); 
size_type find_first_of( const char *str, size_type index = 0 ); 
size_type find_first_of( const char *str, size_type index, size_type num ); 
size_type find_first_of( char ch, size_type index = 0 );

查找在字符串中第一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,如果没找到就返回string::npos 注:npos表示size_t的最大值 
查找在字符串中第一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,最多搜索num个字符。如果没找到就返回string::npos, 
查找在字符串中第一个与ch匹配的字符,返回它的位置。搜索从index开始。

2.std::string line  line.erase(pos,num); 删除字符串中的从pos位置开始的num个字符