как отсортировать масив по алфавиту, буду очень признателен за помощ

#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

class Phones{

    public:

        string model;
        string color;
        int price;

        void setall(){

            string *models = new string[10];
            string *colors = new string[10];
            int *prices = new int[10];

            for(int i = 0; i < 3; i++){
                cout << "enter model" << endl << "enter color" << endl << "enter price" << endl;
                cin >> model
                >> color
                >>price;
                models[i] = model;
                colors[i] = color;
                prices[i] = price;

            }

            
            //sort(models->begin(), models->end());
            /*for (it=models.begin(); it!=models.end(); ++it)
                cout << " " << *it;*/

            for (int j = 0; j < 3; j++)
            {

                cout << models[j] << " " << colors[j] << "  " << prices[j] << endl;
            }

        };
        void print(){
        }

};

int main() {

    Phones a;
    a.setall();


}

Ответы (1 шт):

Автор решения: Harry

У вас же обычный массив, так что...

sort(models, models+10);

for (int i = 0; i < 10; ++i) cout << " " << models[i];

Правда, вы вводите только 3 значения, так что 10 замените на 3.

А еще лучше - воспользуйтесь, например, векторами.

И еще - вы так сортируете только массив models, массивы colors и prices остаются при этом неизменными.

→ Ссылка