You can use resize() when you originally create the vector so that it will contain room for using [] to insert items
vector<int> ay;
ay.resize(10);
for(int i = 0; i < 10; i++)
ay[i] = i;
or you can use an iterator
int main()
{
int count = 0;
std::vector<int> ay;
ay.resize(10);
std::vector<int>::iterator it;
for(it = ay.begin(); it != ay.end(); it++)
*it = count++;
}