fork download
  1. #include <array>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7. std::array<int, 4> high_numbers;
  8. {
  9. std::array<int, 8> some_numbers = { 0, 3, 4, 6, 2, 9, 1, 5 }; // imagine these comme from std::cin
  10. std::sort(some_numbers.begin(), some_numbers.end());
  11. std::copy(some_numbers.begin() + some_numbers.size() / 2, some_numbers.end(), high_numbers.begin());
  12. } // original array disappears just like OP mentioned
  13.  
  14. std::cout << "Tell me where the damn size changes?" << std::endl;
  15. std::for_each(high_numbers.begin(), high_numbers.end(), [](int i) { std::cout << i << " "; });
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
Tell me where the damn size changes?
4 5 6 9