C++实现字符串翻转 源代码如下: #include<iostream> #include<string> using namespace std; int main(){ int n; cin>>n; getchar(); while(n--){ char s[100]; int t = 0; gets(s); for(int i = 0;i<=strlen(s);i++){ if(s[i]==' '||s[i] == '\0'){ std::reverse(s+t,s+i); t = i+1; } } cout<<s<<endl; } }