Hi everyone,
I need to pass a vector to an external function and then have that function read the items within the vector. I'm assuming I have to pass the vector by pointer. Other than that, there's no real reason I'm using a pointer here.
Below is a bit of code which shows what I'm trying to do. Everything works fine except for the "cout << PtrMyVector;" line.
Any suggestions whatsoever will be greatly appreciated!
Thanks,
-George
=================================================
#include <iostream>
#include <vector>
using namespace std;
void ReadMyVector(vector <int>* PtrMyVector)
{
cout << "Vector is: { ";
for (int i=0; i<PtrMyVector->size(); i++)
{
cout << PtrMyVector[i];
cout << ", ";
}
cout << " }";
}
void main()
{
int MyInts[] = {1, 2, 3, 4, 5, 6};
vector<int> MyVector (MyInts, MyInts + sizeof(MyInts) / sizeof(int) );
vector <int>* PtrMyVector = &MyVector;
ReadMyVector( PtrMyVector );
}