fork(4) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. void printPairs(std::vector<int> const& numbers)
  5. {
  6. std::cout << "-----------------------\n";
  7.  
  8. // If the vector is empty, skip the block.
  9. if ( !numbers.empty() )
  10. {
  11. auto end = numbers.cend() - 1;
  12. for (auto it = numbers.cbegin(); it != end; ++it) {
  13. std::cout << '(' << *it << ',' << *(it+1) << ')' << std::endl;
  14. }
  15. }
  16. std::cout << "-----------------------\n\n";
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22. printPairs({}); // Empty argument.
  23. printPairs({10}); // Argument with one item.
  24. printPairs({1, 2, 3, 4}); // Argument with more than one item.
  25. }
  26.  
  27.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
-----------------------
-----------------------

-----------------------
-----------------------

-----------------------
(1,2)
(2,3)
(3,4)
-----------------------