fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. int arr[] = {3, 2, 6, 4};
  8. const int sz = static_cast<int>(sizeof arr / sizeof arr[0]);
  9. std::vector< pair<int, int> > vp(sz); // std::array if size is fixed
  10. for(int i = 0; i < sz; ++i) vp[i] = make_pair(arr[i], i + 1);
  11. sort(vp.begin(), vp.end());
  12. for(int i = 0; i < sz; ++i) cout << ' ' << vp[i].second;
  13. return 0;
  14. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
 2 1 4 3