Dear friends:
     I use the auto varble for the vector double, but could you please how to find the index of i when i loop over the vector.
            vector<double> age;
            for(auto i:age) cout<< " the index of i"<<endl;
Regards
#include <vector>
#include <iostream>
using namespace std;

int main()
{
    vector<double> age{8.2, 7.2, 1.3};
    for(auto i:age)
        cout<< "Value : " << i << endl;

    return 0;
}

Not sure what you mean by "index". I think of the "indexes" as 0, 1, and 2 in this vector. The above program will output 8.2, 7.2, then 1.3, the ELEMENTS of the vector. Which is what I assume you are going for here?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.