1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-31 10:24:23 +03:00

added first insert functions

This commit is contained in:
Niels
2015-07-12 18:28:23 +02:00
parent b2efd50a03
commit 186aefb8f2
13 changed files with 503 additions and 3 deletions

16
doc/examples/insert.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON array
json v = {1, 2, 3, 4};
// insert number 10 before number 3
auto new_pos = v.insert(v.begin() + 2, 10);
// output new array and result of insert call
std::cout << *new_pos << '\n';
std::cout << v << '\n';
}

1
doc/examples/insert.link Normal file
View File

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/s0562du3uk9eMpos"><b>online</b></a>

View File

@ -0,0 +1,2 @@
10
[1,2,10,3,4]

View File

@ -0,0 +1,16 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON array
json v = {1, 2, 3, 4};
// insert number 7 copies of number 7 before number 3
auto new_pos = v.insert(v.begin() + 2, 7, 7);
// output new array and result of insert call
std::cout << *new_pos << '\n';
std::cout << v << '\n';
}

View File

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/kZCcDOrWRsmOCjOn"><b>online</b></a>

View File

@ -0,0 +1,2 @@
7
[1,2,7,7,7,7,7,7,7,3,4]

View File

@ -0,0 +1,19 @@
#include <json.hpp>
using namespace nlohmann;
int main()
{
// create a JSON array
json v = {1, 2, 3, 4};
// create a JSON array to copy values from
json v2 = {"one", "two", "three", "four"};
// insert range from v2 before the end of array v
auto new_pos = v.insert(v.end(), v2.begin(), v2.end());
// output new array and result of insert call
std::cout << *new_pos << '\n';
std::cout << v << '\n';
}

View File

@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/lZeC91nMjP3Npmx7"><b>online</b></a>

View File

@ -0,0 +1,2 @@
"one"
[1,2,3,4,"one","two","three","four"]