vendredi 1 juin 2018

c++ std::sort unexpected behaviour (Runtime Error)

can anyone please tell me why std::sort shows this unexpected behaviour.

This code is giving Runtime Error

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

inline bool compare(string a, string b){
    return a.size() <= b.size();
}

int main(){

        int n = 100;

        string a = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

        vector<string>v;
        for(int i=0; i<n; i++){
            v.push_back(a);
        }

        sort(v.begin(), v.end(), compare);

}

Aucun commentaire:

Enregistrer un commentaire