输入一个字符串,将其逆序后输出。(使用C++,不建议用伪码)

#include <iostream>
#include <string>
using namespace std;

void SetStr(string &str)
{
	int len=str.length();
	char temp;
	for (int i=0;i<len/2;i++)
	{//把字符串的两边一一调换
		temp=str[i];
		str[i]=str[len-1-i];
		str[len-1-i]=temp;
	}
}

int main()
{
	string a;
	cout<<"input"<<endl;
	cin>>a;
	SetStr(a);
	cout<<a<<endl;
	return 0;
}
posted @ 2010-12-01 09:53  瓜蛋  阅读(1032)  评论(5编辑  收藏  举报