-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_dict.cpp
More file actions
31 lines (24 loc) · 861 Bytes
/
example_dict.cpp
File metadata and controls
31 lines (24 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include "ndict.h"
using namespace std;
/*!\brief Simple example of how to use the json parser with the dictionary
* \return 0
*/
int main(){
// Set some simple values
ndict cfg;
cfg["string"]="string";
cfg["float"]=123.456;
// Add nested value
cfg["outer"]["inner"]["value1"]="hello";
// Add array values
cfg["outer"]["inner"]["array"][0]="cruel";
cfg["outer"]["inner"]["array"][1]="world";
// Read back value
cout << "string: " << cfg["string"].getstring() << endl;
cout << "float: " << cfg["float"].getdouble() << endl;
cout << "nested: " << cfg["outer"]["inner"]["value1"].getstring() << endl;
cout << "array[0]: " << cfg["outer"]["inner"]["array"][0].getstring() << endl;
cout << "array[1]: " << cfg["outer"]["inner"]["array"][1].getstring() << endl;
return 0;
}