summaryrefslogtreecommitdiff
path: root/userspace/cpp/testcpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/cpp/testcpp.cpp')
-rw-r--r--userspace/cpp/testcpp.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/userspace/cpp/testcpp.cpp b/userspace/cpp/testcpp.cpp
new file mode 100644
index 0000000..0e89276
--- /dev/null
+++ b/userspace/cpp/testcpp.cpp
@@ -0,0 +1,34 @@
+// constructing vectors
+#include <iostream>
+#include <vector>
+#include <cstring>
+#include <reent.h>
+
+//#undef _REENT_GLOBAL_STDIO_STREAMS
+
+int main()
+{
+ _REENT_INIT_PTR(_impure_ptr);
+
+
+
+
+ // constructors used in the same order as described above:
+ std::vector<int> first; // empty vector of ints
+ std::vector<int> second (4,100); // four ints with value 100
+ std::vector<int> third (second.begin(),second.end()); // iterating through second
+ std::vector<int> fourth (third); // a copy of third
+
+ // the iterator constructor can also be used to construct from arrays:
+ int myints[] = {16,2,77,29};
+ std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
+
+ std::cout << "The contents of fifth are:";
+ for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
+ std::cout << ' ' << *it;
+ std::cout << '\n';
+
+
+
+ return 0;
+}