Try this:
if (S.length() <= 1000 && S.length() != 1)
{
cout << "Times of rotation: ";
cin >> K;
int L = S.length();
for (int ii = 0; ii < K; ii++)
{
char chFirst = S[0];
for(int i = 0; i < L - 1; i++)
S[i] = S[i+1];
S[L - 1] = chFirst;
}
cout << S;
}
A short explanation:
- we save the first character
- loop n- times, where n the rotation is.
- inner loop: replace the first char with the second, the second with the third and so on
- set the first character to the and of the string