c++实现字符串翻转

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

void main()
{
 string str = "012345678";

 //求出字符串的长度
 int len = str.length();

 for (int i = 0; i<len/2; i++)
 {
  //前后交换
  char temp = str[i];
  str[i] = str[len-i-1];
  str[len-i-1] = temp;
 }

 //输出交换后的字符串
 cout<<str<<endl;

}
 
 
转自:
http://zhidao.baidu.com/question/129468929.html

你可能感兴趣的:(c++实现字符串翻转)