]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #include <iostream> |
2 | #include <nlohmann/json.hpp> | |
3 | ||
4 | using json = nlohmann::json; | |
5 | ||
6 | int main() | |
7 | { | |
8 | // create a JSON array | |
9 | json array = {1, 2, 3, 4, 5}; | |
10 | ||
11 | // output element at index 3 (fourth element) | |
12 | std::cout << array[3] << '\n'; | |
13 | ||
14 | // change last element to 6 | |
15 | array[array.size() - 1] = 6; | |
16 | ||
17 | // output changed array | |
18 | std::cout << array << '\n'; | |
19 | ||
20 | // write beyond array limit | |
21 | array[10] = 11; | |
22 | ||
23 | // output changed array | |
24 | std::cout << array << '\n'; | |
25 | } |