accessing a vector<Point3f> element

Hey guys

anyone know how to access an element of the point3f vector

e.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
  vector<Point3f> a;
  a.push_back(Point3f(0,0,0);
  a.push_back(Point3f(0,0,1);
  
  //print first x,y,z element
  cout<<a[0]<<endl;

  //problem in printing the x, y and z value of each one separately
  for(int i=0;i<a.size();i++)
  {
    //print x value of ith point3f element
    cout<<a.at<float>(i,0,0);
     
    //same for y and z instead use (i,0,1) and (i,1,0);
   }

but it doesn' work firstly because it says can't use typename i.e. <float>

any help
thanks
Last edited on
You should define an overloaded operator << for class Point3f
Last edited on
<< is for cout.

e.g. if i wanted x value
x=a.at<float>(i,0,0);

i just want to find a way to access x,y,z values.

i tried a.at<<float>>(i,0,0)

but still error
`a' is a std::vector
`a[0]', `a[1]' are Point3f
that was soo easy and so much better than a.at

a[0].x will give me the x value for the 0th element.
thanks
closed account (S6k9GNh0)
at and operator[] do two different things.
what's the difference?
There is a reference here :)
http://www.cplusplus.com/reference/vector/vector/

at() throws an exception if the value is out of range, [] might just shut down your program.
oh, i see
Topic archived. No new replies allowed.