String 字符串中的移位字符

String 字符串中的移位字符,string,character,shift,String,Character,Shift,我正在尝试将字符串中的字符“n”次向左或向右移动。例如,将“hello”移到右边的3是“lohel”。另一个例子是“hello”向左移动2将是“llohe” 到目前为止,我有这个,但它只适用于左移1: strUserInput[0] = strUserInput[strUserInput.length()]; for (unsigned int i = 0; i < strUserInput.length(); i++){ strUserInput[i] = s

我正在尝试将字符串中的字符“n”次向左或向右移动。例如,将“hello”移到右边的3是“lohel”。另一个例子是“hello”向左移动2将是“llohe”

到目前为止,我有这个,但它只适用于左移1:

strUserInput[0] = strUserInput[strUserInput.length()];

    for (unsigned int i = 0; i < strUserInput.length(); i++){
        strUserInput[i] =  strUserInput[i + 1];
    }
strUserInput[0]=strUserInput[strUserInput.length()];
for(无符号整数i=0;i
向左移位意味着在字符串末尾追加第一个字符;向右移动意味着将最后一个字符追加到列表的第一个字符;您可以使用循环确定“n”。第一个字符和最后一个字符之间的其余字符的移位情况如何?您使用的是什么语言?@Timm_oh使用子字符串获取最后一个字符(或第一个字符)和字符串的其余部分,并重新排列它们。