讲一个字符串逆袭输出,请问哪错了?
#include<iostream>#include<string>
using namespace std;
void main()
{
int n,i;
string string1,string2;
cin>>string1;
n=sizeof(string1);
for(i=1;i<=n;i++);
{
string2[i]=string1[n-i+1];
cout<<string2<<endl;
}
}
#include <iostream> #include <string> using namespace std; int main( void ) { string s; cin >> s; string s2( s.size(), ' ' ); for( size_t i=0; i!=s.size(); ++i ) s2[i] = s[s.size()-i-1]; cout << s2 << endl; }
#include <iostream> #include <string> #include <algorithm> #include <iterator> using namespace std; int main( void ) { string s; cin >> s; copy( s.rbegin(), s.rend(), std::ostream_iterator<char>(cout,"") ) = '\n'; }