xref: /third_party/json/docs/examples/insert__count.cpp (revision c5f01b2f)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ciusing json = nlohmann::json;
5c5f01b2fSopenharmony_ci
6c5f01b2fSopenharmony_ciint main()
7c5f01b2fSopenharmony_ci{
8c5f01b2fSopenharmony_ci    // create a JSON array
9c5f01b2fSopenharmony_ci    json v = {1, 2, 3, 4};
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci    // insert number 7 copies of number 7 before number 3
12c5f01b2fSopenharmony_ci    auto new_pos = v.insert(v.begin() + 2, 7, 7);
13c5f01b2fSopenharmony_ci
14c5f01b2fSopenharmony_ci    // output new array and result of insert call
15c5f01b2fSopenharmony_ci    std::cout << *new_pos << '\n';
16c5f01b2fSopenharmony_ci    std::cout << v << '\n';
17c5f01b2fSopenharmony_ci}
18

Indexes created Thu Nov 07 10:32:03 CST 2024