-1
목표는 sentence.find('and')
을 사용하여 "ands" 문자열의 모든 위치를 찾는 것입니다. int
변수도 사용해야합니다. 내가 지금까지했던 어떤C++ string.find ('')
는 :
#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로 계산하지만 각 개별 "와"의 위치를 찾아야합니다. 도와주세요, 사전에
감사
설명서를 사용하십시오. http://www.cplusplus.com/reference/string/string/find/ –