xxxxxxxxxx
#include <iostream>
#include <string>
void printPrefixes(string s)
{
int n = s.length();
for(int i=0;i<n;i++)
{
cout<< s.substr(0,i+1)<<endl;
}
}
int main()
{
string s = "abcd";
printPrefixes(s);
return 0;
}
xxxxxxxxxx
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s("hello hello");
int count = 0;
size_t nPos = s.find("hello", 0); // first occurrence
while(nPos != string::npos)
{
count++;
nPos = s.find("hello", nPos + 1);
}
cout << count;
};
xxxxxxxxxx
void printsubstr(string s, int n){
for(int i=0;i<n;i++){
for(int j=1;j<=n-i;j++){
cout<<s.substr(i,j)<<endl;
}
}
}