C++ 字符串.查找()
C++ string.find(' ')
目标是使用 sentence.find('and')
在字符串中找到" ands" 的所有位置。int
变量也必须使用。
我到目前为止所做的:
#include <iostream>
#include <string>
using namespace std;
int main() {
string sentence;
int first, second, third;
sentence = "My name is Ryan and I like sports and music and movies";
first = sentence.find('and');
second = sentence.find('and');
third = sentence.find('and');
cout << "Position of first and is: " << first << endl;
cout << "Position of second and is: " << second << endl;
cout << "Position of third and is: " << third << endl;
system("pause");
return 0;
}
它仅计算出所有3 的18,但是我需要找到每个单个"answers" )的位置。请帮助,
预先感谢
find
的第二个(显然是可选的)参数指定在字符串中开始搜索的位置;用它跳过您已经发现的事件。
相关文章:
- 使用正则表达式regex_search在字符串中查找字符串
- 一个函数,用于查找字符串1包含字符串2 c++的次数
- 在 c++ 中查找字符串中没有循环的数字总和
- 查找字符串可以减少到 0 的步骤数
- C++ 查找字符串中存在的元素向量
- 查找字符串中最常见的字母
- C++使用旧编译器GCC 4.4.0在结构列表中查找字符串
- 查找字符串是否包含字符串向量的任何一个元素的最佳方法
- 如何使用字符串流查找字符串中的整数总和?
- 穿过链接列表以查找字符串
- 查找字符串中存在的不同字符
- 如何使用 std::find 从向量的第一个元素中查找字符串<字符串对<字符串、字符串> >类型?
- 如何从C++的输入中查找字符串并将其替换为另一个字符串
- C++在多个字符串中查找字符串
- 使用std :: quare_range查找字符串向量中发生的前缀范围
- 在字符串列表中查找字符串,然后将字符串设置为找到的字符串?
- 尝试在类的向量中查找字符串
- 是否有一种算法可以查找字符串中任何指定字符的第一次出现
- 在.txt中查找字符串并获取C++中的行内容
- 如何在考虑标点符号的同时在文件中查找字符串