在以下程序中旋转字符串时出现运行时错误。请帮忙
代码中没有编译错误
#include <iostream>
#include <cstring>
using namespace std;
void reverseString(char* str, int start, int end)
{
int front = start;
int back = end;
while (front < back)
{
/* swap two variables without
using a temporary one.*/
str[front] ^= str[back];
str[back] ^= str[front];
str[front] ^= str[back];
++front;
--back;
}
return;
}
这部分用于旋转字符串
void rotateString(char* str, int k)
{
if (!str || !*str)
return;
int len = strlen(str);
/*Rotating a string by it's length is string itself.*/
k %= len;
reverseString(str, 0, len-1);
reverseString(str, 0, k-1);
reverseString(str, k, len-1);
cout<<str;
return;
}
int main() {
rotateString("abcde",2);
return 0;
}