Advertisement
bappi2097

Substring

Jul 6th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. // C++ program to print all possible
  2. // substrings of a given string
  3. #include<bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. // Function to print all sub strings
  9.  
  10. void subString(string s, int n)
  11. {
  12.  
  13. // Pick starting point in outer loop
  14.  
  15. // and lengths of different strings for
  16.  
  17. // a given starting point
  18.  
  19. for (int i = 0; i < n; i++)
  20.  
  21. for (int len = 1; len <= n - i; len++)
  22.  
  23. cout << s.substr(i, len) << endl;
  24. }
  25.  
  26.  
  27. // Driver program to test above function
  28.  
  29. int main()
  30. {
  31.  
  32. string s = "abcd";
  33.  
  34. subString(s,s.length());
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement