C/C++

Никак не получается найти решение задачи

struct product
{
string name;
int category;
string date;
string date_manufacture;
int shelf_life;
int price;
int count;
}
int main(int argc[])

{
product products[] = {
{ "White bread", 1, "21.12.2022", "21.12.2022", 11, 100, 18 },
{ "wheat bread", 3, "21.12.2022", "21.12.2022", 9, 70, 118 },
{ "rye bread", 4, "21.12.2022", "21.12.2022", 16, 60, 161 },
{ "pretzel bread", 8, "21.12.2022", "21.12.2022", 18, 71, 111 },
{ " pite bread", 6, "21.12.2022", "21.12.2022", 3, 84, 121 },
{ "challah bread", 7, "21.12.2022", "21.12.2022", 21, 26, 131 },
{ "french bread", 10, "21.12.2022", "21.12.2022", 17, 34, 141 },
{ "croissant bread", 12, "21.12.2022", "21.12.2022", 1, 89, 17 },
{ "donut bread", 11, "21.12.2022", "21.12.2022", 22, 77, 9 },
{ "sweet bread", 13, "21.12.2022", "21.12.2022", 11, 44, 65 },
{ "italian bread", 14, "21.12.2022", "21.12.2022", 18, 76, 45 },
{ "russian bread", 16, "21.12.2022", "21.12.2022", 14, 82, 42 },
{ "african bread", 15, "21.12.2022", "21.12.2022", 13, 45, 93 },
{ "japan bread", 7, "21.12.2022", "21.12.2022", 17, 32, 64 },
{ "french bread", 9, "21.12.2022", "21.12.2022", 19, 99, 12 },
{ "belgian bread", 22, "21.12.2022", "21.12.2022", 19, 62, 35 },
{ "british bread", 17, "21.12.2022", "21.12.2022", 16, 53, 48 },
{ "american bread", 14, "21.12.2022", "21.12.2022", 14, 57, 27 },
{ "spanish_breath bread", 18, "21.12.2022", "21.12.2022", 12, 61, 86 },
{ "black bread", 21, "21.12.2022", "21.12.2022", 24, 34, 43 }
};
}

Надо вывести этот массив структур в порядке по возрастанию количества букв в поле name. Как это сделать?
XV
Xcho Vardanyan
21
Например, так:
 #include 
#include

using namespace std;

struct product {
string name;
int category;
string date;
string date_manufacture;
int shelf_life;
int price;
int count;
};

int main() {
// создаём нормальный вектор, а не C-style пародию на массив
auto products = vector{
{"White bread", 1, "21.12.2022", "21.12.2022", 11, 100, 18},
{"wheat bread", 3, "21.12.2022", "21.12.2022", 9, 70, 118},
{"rye bread", 4, "21.12.2022", "21.12.2022", 16, 60, 161},
{"pretzel bread", 8, "21.12.2022", "21.12.2022", 18, 71, 111},
{"pite bread", 6, "21.12.2022", "21.12.2022", 3, 84, 121},
{"challah bread", 7, "21.12.2022", "21.12.2022", 21, 26, 131},
{"french bread", 10, "21.12.2022", "21.12.2022", 17, 34, 141},
{"croissant bread", 12, "21.12.2022", "21.12.2022", 1, 89, 17},
{"donut bread", 11, "21.12.2022", "21.12.2022", 22, 77, 9},
{"sweet bread", 13, "21.12.2022", "21.12.2022", 11, 44, 65},
{"italian bread", 14, "21.12.2022", "21.12.2022", 18, 76, 45},
{"russian bread", 16, "21.12.2022", "21.12.2022", 14, 82, 42},
{"african bread", 15, "21.12.2022", "21.12.2022", 13, 45, 93},
{"japan bread", 7, "21.12.2022", "21.12.2022", 17, 32, 64},
{"french bread", 9, "21.12.2022", "21.12.2022", 19, 99, 12},
{"belgian bread", 22, "21.12.2022", "21.12.2022", 19, 62, 35},
{"british bread", 17, "21.12.2022", "21.12.2022", 16, 53, 48},
{"american bread", 14, "21.12.2022", "21.12.2022", 14, 57, 27},
{"spanish_breath bread", 18, "21.12.2022", "21.12.2022", 12, 61, 86},
{"black bread", 21, "21.12.2022", "21.12.2022", 24, 34, 43}
};

// сортируем
sort(products.begin(), products.end(),
[](product &a, product &b) { return a.name.size() < b.name.size(); });

// выводим
for (auto &p: products) {
cout
Андрей Пак
Андрей Пак
78 350
Лучший ответ