I'm trying to solidify my understanding of some vector concepts.
1) interators are "smart access" in that they can keep track of the array
position and size.
2) the access element operator [] is the "dumb" access to the vector.
Also, I was experimenting with ways to dump the contents of a vector into an array of the same size.
Here's how i got it to happen:
#include <iostream>
#include <vector>
using namespace std;
vector<int> vint;
int input =1 ;
int main()
{
cout << "Enter an integer (Enter 0 to exit) ";
while(input)
{
cin >> input;
vint.push_back(input);
}
size_t n = vint.size();
int arr[n];
cout << "the vector content is: ";
for ( int j = 0; j < n; j++)
{
arr[j] = vint[j];
cout << vint[j] << " ";
}
cout << endl;
cout << "The vector size is: " << vint.size() << endl;
cout << "The content of the array is: "<< endl;
for (int j=0; j < n; j++)
cout << arr[j] << " ";
cout << endl;
return 0;
}
I tried to do direct assignment:
arr=vint // why won't this work? essentially they're both arrays- or so i thought.
Then I got busted trying to do this:
for (it = iterator vint.begin; it < iterator vint.end() ; it++)
arr[it] = *it; // OK, I guess the iterator is a different animal than an integer? Not to mention the possible scoping problem?
It didn't work if I used an actual integer either like this:
arr[x] = *it // where int x is part of a nested loop. I dont understand why this didn't work since I CAN do:
cout << *it // this will provide the dereferenced pointer data
What's the story here?
I sure this all seems twisted to folks who are comfortable with the nuances, but I would appreciate some clarifications.
I learn best by tinkering...