C++ 用vector创建字符串数组对象,编写函数,使得数组中的字符串按大小排序

#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

void maopaopaixu(string arr){
//	string c;
	char c[50];
	for(int i=0;i<arr.length()-1;i++){
		for(int j=0;j<arr.length()-1-i;j++){
			if(strcmp(arr[j],arr[j+1])>0){
				strcpy(c,arr[j+1]);
				strcpy(arr[j+1],arr[j]);
				strcpy(arr[j],c); 
			}
		}
	}
	for(int i=0;i<5;i++){
		cout<<arr[i]<<endl;
	}
}

int main(){
	vector<string>arr(5);
	cout<<"请输入英文句子:"<<endl;
	for(int i=0;i<5;i++){
		getline(cin,arr[i]);
	}
	for(int i=0;i<5;i++){

		cout<<arr[i]<<endl;
	}
//	maopaopaixu(arr);
} 

如题,完成了vector的初始化,但是在自定义的函数不知道怎么去数组中的字符串按大小排序

题目要求:

用vector创建字符串数组对象,长度为5(30分)。

  (1)手动输入以下5个英文句子,存入数组对象:

Do one thing at a time, and do well.

Action speak louder than words.

Never put off what you can do today until tomorrow.

Like author, like book.

Knowledge makes humble, ignorance makes proud.

(2)编写函数,使得数组中的字符串按大小排序(按字符串比较的规则)。

(3)输出排序后的句子,并显示其长度。

 

求教!

你好,我的程序符合你的要求吗?

#include<iostream>
#include<vector>
using namespace std;
vector<string>arr;
int strcomp(int a, int b){
    int i,j;
    auto fir = arr.begin()+a;
    auto sec = arr.begin()+b;
    for(i=0,j=0; (*fir)[i]!='\0' && (*sec)[j]!='\0'; i++,j++)
        if( (*fir)[i] != (*sec)[j] ) return (*fir)[i]-(*sec)[j];
    return (*fir).size()-(*sec).size();
}
void swap(int i){
    string * p = arr.data()+i;
    string temp = p[0];
    p[0] = p[1];
    p[1] = temp;
}
void sort(vector<string>a){
    for(int i=0;i<a.size()-1;i++)
        for(int j=0;j<a.size()-1-i;j++)
            if(strcomp(j, j+1)>0){
                swap(j);
            }
}
int main(){
    string str;
    cout<<"请输入英文句子:"<<endl;
    for(int i=0;i<5;i++){
        getline(cin, str);
        arr.push_back(str);
    }
    sort(arr);
    for(int i=0;i<5;i++){
        cout<<arr[i]<<endl;
    }
    for(int i=0;i<5;i++){
        cout<<arr[i].size()<<endl;
    }
}
/*
Do one thing at a time, and do well.
Action speak louder than words.
Never put off what you can do today until tomorrow.
Like author, like book.
Knowledge makes humble, ignorance makes proud.
 */

 

 

std::vector<string>::iterator fir = arr.begin()+a;
std::vector<string>::iterator sec = arr.begin()+b;