Horje
c++ find index of all occurrences in string Code Example
c++ find index of all occurrences in string
// C++ program to find indices of all
// occurrences of one string in other.
#include <iostream>
using namespace std;
void printIndex(string str, string s)
{
 
    bool flag = false;
    for (int i = 0; i < str.length(); i++) {
        if (str.substr(i, s.length()) == s) {
            cout << i << " ";
            flag = true;
        }
    }
 
    if (flag == false)
        cout << "NONE";
}
int main()
{
    string str1 = "GeeksforGeeks";
    string str2 = "Geeks";
    printIndex(str1, str2);
    return 0;
}




Cpp

Related
sass set variable if not defined Code Example sass set variable if not defined Code Example
c++ define constant in class header Code Example c++ define constant in class header Code Example
Statements Code Example Statements Code Example
options select from array Code Example options select from array Code Example
get list of files in directory c++ Code Example get list of files in directory c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11