C++ 中查找 'ab' 字符串
'ab' 串是指字符串中包含 'ab' 字符序列的部分。在 C++ 中,可以使用字符串的 find 函数来查找 'ab' 字符序列的位置。以下是一个示例代码:
#include <iostream>
#include <string>
int main() {
std::string str = 'ab串c++';
std::size_t found = str.find('ab');
if (found != std::string::npos) {
std::cout << '找到了'ab'串,位置为:' << found << std::endl;
} else {
std::cout << '未找到'ab'串' << std::endl;
}
return 0;
}
上述代码首先定义了一个字符串str,然后使用find函数查找字符串中是否包含 'ab' 字符序列。如果找到了 'ab' 串,就会输出其位置,否则输出未找到。
原文地址: https://www.cveoy.top/t/topic/bFyc 著作权归作者所有。请勿转载和采集!