输出给定字串的全部连续子串。
比如对给给定字符串 “abcd",应该打印出:a,b,c,d,ab,bc,cd,abc,bcd,abcd等。
比如对给给定字符串 “abcd",应该打印出:a,b,c,d,ab,bc,cd,abc,bcd,abcd等。
/*输出给定字串的全部连续子串。
比如对给给定字符串 “abcd",应该打印出:a,b,c,d,ab,bc,cd,abc,bcd,abcd等。*/
/*方法1:使用标准库 string*/
#include <iostream>
#include <string>
using namespace std;
void print(string s)
{
if(s.empty())
return;
string temp;
for(string ::size_type index = 0; index != s.size(); ++ index)
{
temp = "";
for(string :: size_type index1 = index; index1 != s.size(); ++ index1)
{
temp += s[index1];
cout << temp << endl;
}
}
}
int main()
{
string s;
cout << "please input the string:" << endl;
getline(cin, s);
cout << "the print string is:" << endl;
print(s);
system("pause");