cend.cpp 413 B

12345678910111213141516171819
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create an array value
  7. json array = {1, 2, 3, 4, 5};
  8. // get an iterator to one past the last element
  9. json::const_iterator it = array.cend();
  10. // decrement the iterator to point to the last element
  11. --it;
  12. // serialize the element that the iterator points to
  13. std::cout << *it << '\n';
  14. }