C++实现字符串单词的倒序 string 实现

#include <iostream>
#include “string.h”
#include <stdlib.h>

using namespace std;

void r(string str){
int len = str.size();
string l;
int start = 0;
int end = len;
while(len>0){
len–;
if(str[len] == 0)
continue;
if(str[len] == ‘ ‘){
start = len + 1;
string t = str.substr(start,end-start);
l.append(t).append(” “);
end = len;
}
if(len == 0){
start = len;
string t = str.substr(start,end-start);
l.append(t);
}
}
cout<<l.c_str()<<endl;
}

void main()
{
string str = “Sum is a student”;
r(str);
}