看看这道题啊,好难啊!!
编写一个函数,作用是把一个char组成的字符串循环右移N个。比如原来是“abcdefghi”,如果N=2,移位后是“hiabcdefg”.
瞎弄了一个,不过用的是string ,不是char,对不对不要笑话呀
程序代码:
#include <string> #include <iostream> int main( ) { using namespace std; string str1 ("abcdefghijklmn"); cout << "The original string str1 is: \n " << str1 << endl << endl; int n; cin >> n; basic_string <char> str2 = str1.substr ( 0 , str1.size()-n ); cout << "The substring str1 copied is: " << str2 << endl << endl; basic_string <char> str3= str1.substr (str1.size()-n ); cout << "The substring str1 copied is :" << str3 << endl << endl; string str4; str4 = str3 + str2; cout << "New str:" << str4 <<endl; system("pause"); }
[ 本帖最后由 lscalin 于 2010-5-24 18:11 编辑 ]