Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- void printn(int n)
- {
- cout << n << " ";
- }
- int main()
- {
- string string1, string2;
- int pos = -1;
- vector<int> lists;
- cout << "Enter a string: \n";
- getline(cin, string1);
- cout << "\nEnter a string to find: \n";
- getline(cin, string2);
- for(;;)
- {
- pos = string1.find(string2, pos+1);
- if (pos != string::npos)
- lists.push_back(pos+1);
- else
- break;
- }
- if (!lists.empty())
- {
- cout << "\nString found at position/s: ";
- for_each(lists.begin(), lists.end(), printn);
- }
- else
- {
- cout << "\nString not found.";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement