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.

10th Jan 2025, 6:00 AM
TeaserCode
3 Antworten
+ 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 ... } }
10th Jan 2025, 5:00 PM
Buterbrod:)
Buterbrod:) - avatar
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;
10th Jan 2025, 7:37 PM
Brian
Brian - avatar
0
How many loops should it be used at least?
11th Jan 2025, 2:20 AM
TeaserCode