Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to grab each character from a string 
Cpp :: comparator priority queue c++ 
Cpp :: il2cpp stuck unity 
Cpp :: add matic mainnet to metamask mobile 
Cpp :: CRED Coins codechef solution in c++ 
Cpp :: how to take full sentence in c++ 
Cpp :: operator precedence in cpp 
Cpp :: Translation codeforces in c++ 
Cpp :: C++ program for Celsius to Fahrenheit and Fahrenheit to Celsius conversion using class 
Cpp :: how to remove the scroll bar in pyqt6 
Cpp :: C++ Program to Find the Range of Data Types using Macro Constants 
Cpp :: Find duplicates in an array geeks for geeks solution in cpp 
Cpp :: what library is rand in c++ 
Cpp :: balanced parentheses 
Cpp :: C++ String Concatenation Example 
Cpp :: how to print a word in c++ 
Cpp :: flag of georgia 
Cpp :: namespace file linking c++ 
Cpp :: Converting Strings to Numbers in C/C++ 
Cpp :: c++ memory address 
Cpp :: sum of n natural numbers 
Cpp :: Basic Makefile C++ 
Cpp :: ? in cpp 
Cpp :: print all subsequences 
Cpp :: binary to decimal online converter 
Cpp :: ifstream file (“code2.txt”); dev C++ 
Cpp :: c++ tuple push_back 
Cpp :: two dimensional array A[N,M] with the random numbers from 10 to 90. 
Cpp :: ejemplo 
Cpp :: cpp how to add collisions to boxes 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =