for (size_t pos = text.find(pattern, 0); pos != string::npos; pos = text.find(pattern, pos)) { cout << "pattern found at " << pos << "\n"; ++pos; }