0
Write substrings of the string!
String s="abcdefgh", I would like to get these substrings a, b, c, d, e, f, g, h, ab, cd, ef, gh, abc, def, abcd, efgh, abcde, abcdef, abcdefg, abcdefgh. I need your help to do do this.
3 Respostas
+ 1
You can use 2 for loops
// first to find out how many
// letters in a string to cut
for (;;) {
// the second one, to cut out the number
// of letters that the first loop gives
for (;;) {
// some code ...
}
}
0
TeaserCode you may use nested loops as Buterbrod:) recommended. Or you may use a single loop and use the substr(start, len) string method call, where the substring length is given by the loop index.
cout << s.substr(0, i) << endl;
0
How many loops should it be used at least?