Number of substrings of a string | CPP program to count number of substrings of a string ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countNonEmptySubstr ( string str ) { int n = str . length ( ) ; return n * ( n + 1 ) / 2 ; } int main ( ) { string s = " abcde " ; cout << countNonEmptySubstr ( s ) ; return 0 ; }