Skip to content

Commit 62df0df

Browse files
committedAug 4, 2017
Added example code
1 parent da58076 commit 62df0df

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎example.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
#include "dynvars.hpp"
3+
4+
int main(){
5+
6+
// Make an object to hold your data
7+
DynVars myData;
8+
9+
// Create a new variable i
10+
myData.newVariable("i");
11+
12+
// Assign a value to the new variable
13+
myData.writeVariable("i", 5);
14+
15+
// Print the value of our variable to the screen
16+
std::cout << myData.readVariable<int>("i") << std::endl;
17+
18+
// Why not use a pointer to make changes to our variable?
19+
int* i = myData.getPointer<int>("i");
20+
21+
// Change the value of our variable using the pointer
22+
*i = 10;
23+
24+
// Both results are the same
25+
std::cout << *i << " = " << myData.readVariable<int>("i") << std::endl;
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)
Please sign in to comment.