Why is is showing error in rotating the strings of larger length?
This is quite simple your for
loop has condition which is never false
for this input. So you are increasing i
beyond size of s
(double of size of s1
).
Note common part of this two strings is: zqpquwjhuftohawpfegsjvnxwipwqlswvawogjuyiqtzsgpwgosegmuuhpzwchejuiitumyescxxyecnsatcbfpseqzowvdjyvchg
.
Difference is:
-
s1
has in front:ndafmffmuuwj
-
s2
has in backL:avqnonmkwgqp
So s1
is not rotation of s2
that is why codition in for
is never fasle
.
This is the reason std::basic_string::substr
throws an exception.
Live demo.
Some fix.
And here is better way to do it.