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, 2025 by avibootz

Related questions

1 answer 117 views
1 answer 118 views
3 answers 154 views
154 views asked Feb 23, 2023 by avibootz
1 answer 154 views
1 answer 120 views
1 answer 166 views
...