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:
16
doc/examples/insert.cpp
Normal file
16
doc/examples/insert.cpp
Normal 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
1
doc/examples/insert.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/s0562du3uk9eMpos"><b>online</b></a>
|
2
doc/examples/insert.output
Normal file
2
doc/examples/insert.output
Normal file
@ -0,0 +1,2 @@
|
||||
10
|
||||
[1,2,10,3,4]
|
16
doc/examples/insert__count.cpp
Normal file
16
doc/examples/insert__count.cpp
Normal 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';
|
||||
}
|
1
doc/examples/insert__count.link
Normal file
1
doc/examples/insert__count.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/kZCcDOrWRsmOCjOn"><b>online</b></a>
|
2
doc/examples/insert__count.output
Normal file
2
doc/examples/insert__count.output
Normal file
@ -0,0 +1,2 @@
|
||||
7
|
||||
[1,2,7,7,7,7,7,7,7,3,4]
|
19
doc/examples/insert__range.cpp
Normal file
19
doc/examples/insert__range.cpp
Normal 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';
|
||||
}
|
1
doc/examples/insert__range.link
Normal file
1
doc/examples/insert__range.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/lZeC91nMjP3Npmx7"><b>online</b></a>
|
2
doc/examples/insert__range.output
Normal file
2
doc/examples/insert__range.output
Normal file
@ -0,0 +1,2 @@
|
||||
"one"
|
||||
[1,2,3,4,"one","two","three","four"]
|
Reference in New Issue
Block a user