Hey, I don't know if you guys are still subscribed to this thread, but how do I pass my special vector to another function?
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 31 32 33 34 35 36 37
|
#include <iostream>
#include <vector>
using namespace std;
void init(vector<int> & vec);
void print(const vector<int> & vec);
const int SIZE=4;
int main()
{
vector<int> my_int_vector;
init(my_int_vector);
print(my_int_vector);
cout << "\nhit enter to quit...";
cin.get();
return 0;
}
void init(vector<int> & vec)
{
vec.resize(SIZE);
for (int i=0; i<vec.size(); i++)
vec[i]=(i+1)*10;
}
void print(const vector<int> & vec)
{
for (int i=0; i<vec.size(); i++)
{
cout << "vector[" << i << "]=";
cout << vec[i] << endl;
}
}
|
Last edited on