简介
在C++里 查找字符串位置,可以用到 find 和 rfind,一个从头开找,另个是从尾找。
简单例子
#include <iostream>
using namespace std;
int main()
{
string str = "Hello, World!";
unsigned long f = str.find("l", 4); // 从头偏移4位 就找到World里的l了
unsigned long r = str.rfind("l", 4);// 从尾偏移4位 就找到Hello里的l了
cout << f << "," << r << endl;
return 0;
}输出:10,3
评论 (0)