fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <list>
  4.  
  5.  
  6. int main()
  7. {
  8. std::list<int> nums = {1, 2, 3, 4, 5};
  9. auto x = std::find(nums.begin(), nums.end(), 4);
  10. auto &ref = *x;
  11.  
  12. std::cout << *x << std::endl;
  13.  
  14. nums.erase (std::find(nums.begin(), nums.end(), 3));
  15. for (auto &i : nums)
  16. std::cout << i << std::endl;
  17.  
  18. std::cout << *x << std::endl;
  19. std::cout << ref << std::endl;
  20. }
  21.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
4
1
2
4
5
4
4