Program to print all substrings of a given string | C ++ program to print all possible substrings of a given string ; Function to print all sub strings ; Pick starting point in outer loop and lengths of different strings for a given starting point ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void subString ( string s , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) cout << s . substr ( i , len ) << endl ; } int main ( ) { string s = " abcd " ; subString ( s , s . length ( ) ) ; return 0 ; }