How to use STL sort algorithm directly on a regular C style array in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <iterator>

int main() {
    int array[] = {4, 6, 0, 9, 2, 8, 7, 3};

    std::sort(std::begin(array), std::end(array));

    for (auto it = std::begin(array); it != std::end(array); ++it) {
        std::cout << *it << " ";
    }
}



/*
run:
 
0 2 3 4 6 7 8 9 
 
*/


 



answered Mar 2 by avibootz

Related questions

1 answer 88 views
3 answers 108 views
108 views asked Feb 23, 2023 by avibootz
1 answer 113 views
1 answer 82 views
1 answer 124 views
...