给我个思路就行,实在不会写了
例如:
hello world就变成world hello
稍等,我帮你写一个
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
cout << "请输入一个字符串:" << endl;
getline(cin, str);
int i = 0;
while (i < str.size() && str[i] != ' ') {
i++;
}
if (i < str.size()) {
str = str.substr(i + 1) + ' ' + str.substr(0, i);
}
cout << "变换后的字符串为:" << str << endl;
return 0;
}