std::string str = "abcdefghijklmn"
std::string str2 = "defg"
判断str是否包含str2:
std::string::size_type postion = str.find(str2);
如果position == npos 则,不包含字串;反之,包含
本文介绍如何使用C++中的std::string类判断一个字符串是否包含另一个子串,通过使用find()函数来定位子串的位置,并通过返回的std::string::size_type类型值来判断是否存在。
std::string str = "abcdefghijklmn"
std::string str2 = "defg"
判断str是否包含str2:
std::string::size_type postion = str.find(str2);
如果position == npos 则,不包含字串;反之,包含
1万+
7732
3万+
3825
8250
2134

被折叠的 条评论
为什么被折叠?