Sorting infile

I have alot of array and i want to sort it by character.
Example string=model[15];
first i have this

DS-7208HGHI-SH
DS-7232HGHI-SH
DS-7204HGHI-SH
DS-7216HGHI-SH

and I want this result

DS-7204HGHI-SH
DS-7208HGHI-SH
DS-7216HGHI-SH
DS-7232HGHI-SH

is there anyway to do it?

sorry for bad english.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
    using std::begin; using std::end;
    std::string model[] {
        "DS-7208HGHI-SH",
        "DS-7232HGHI-SH",
        "DS-7204HGHI-SH",
        "DS-7216HGHI-SH",
    };
    std::sort(begin(model), end(model));
    for(const auto& s: model)
        std::cout << s << '\n';
}
DS-7204HGHI-SH
DS-7208HGHI-SH
DS-7216HGHI-SH
DS-7232HGHI-SH
http://coliru.stacked-crooked.com/a/94a0652cec47f8c7
Thanks MiiNiPaa,but i don't clear this point this point

for(const auto& s: model)

Can you explain me?

It's the C++11 range based for loop.
http://en.cppreference.com/w/cpp/language/range-for
Topic archived. No new replies allowed.