I have an array of 5 words. I find the letters I need in these words and change them. And the second task is to take the last 2 letters from each word and put them into a substring. Those. we take the word maybe and we need to take the letters be from it, then bring them to the screen.
#include <vector> #include <algorithm> using namespace std; void myfunction(string& i) { for (auto idx = i.find("ab"); idx != string::npos; idx = i.find("ab")) { i.replace(idx, 2, "ccc"); } } int main() { vector<string> v; v.push_back("soon able brabus strong crab"); ostream_iterator<string> printit(cout, " "); cout << "Before replacing" << endl; copy(v.begin(), v.end(), printit); for_each(v.begin(), v.end(), myfunction); cout << endl; cout << "After replacing" << endl; copy(v.begin(), v.end(), printit); cout << endl; system("pause"); return 0; } I found how easy it is to remove words with certain letters, found how to search for words with non-recurring letters. But how to find the 2nd last letters in the words array, and then display them on the screen, I could not.