at__size_type.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 
00003 using json = nlohmann::json;
00004 
00005 int main()
00006 {
00007     // create JSON array
00008     json array = {"first", "2nd", "third", "fourth"};
00009 
00010     // output element at index 2 (third element)
00011     std::cout << array.at(2) << '\n';
00012 
00013     // change element at index 1 (second element) to "second"
00014     array.at(1) = "second";
00015 
00016     // output changed array
00017     std::cout << array << '\n';
00018 
00019     // try to write beyond the array limit
00020     try
00021     {
00022         array.at(5) = "sixth";
00023     }
00024     catch (std::out_of_range& e)
00025     {
00026         std::cout << "out of range: " << e.what() << '\n';
00027     }
00028 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:01