Passing a vector/array from unmanaged C++ to C#

As long as the managed code does not resize the vector, you can access the buffer and pass it as a pointer with (for C++0x) or &vector[0]. This results in a zero-copy system. Example C++ API: #define EXPORT extern “C” __declspec(dllexport) typedef intptr_t ItemListHandle; EXPORT bool GenerateItems(ItemListHandle* hItems, double** itemsFound, int* itemCount) { auto … Read more

Initializer-list-constructing a vector of noncopyable (but movable) objects

Maybe this clause from explains it (my emphasis): An object of type std::initializer_list is constructed from an initializer list as if the implementation allocated an array of N elements of type E, where N is the number of elements in the initializer list. Each element of that array is copy-initialized with the corresponding element … Read more

How to read a file into vector in C++?

Your loop is wrong: for (int i=0; i=((Main.size())-1); i++) { Try this: for (int i=0; i < Main.size(); i++) { Also, a more idiomatic way of reading numbers into a vector and writing them to stdout is something along these lines: #include <iostream> #include <iterator> #include <fstream> #include <vector> #include <algorithm> // for std::copy int … Read more