chapter4-1.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
源码类别:

STL

开发平台:

C/C++

  1. //文件名:chapter4-1.cpp
  2. #include <iostream.h>
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. class Point
  7. {
  8. public:
  9. int id;
  10. char *context;
  11. double scroe;
  12. Point(int i, char *j,double d)
  13. { id=i;
  14. context=j;
  15. scroe=d;
  16. }
  17. Point(){};
  18. };
  19. std::vector<Point> cities;
  20. void add_points(Point sentinel){ cities.push_back(sentinel);}
  21. void main()
  22. {
  23. Point Mypoint(0,"test0",0.1);
  24. add_points(Mypoint);
  25. Point Mypoint0(1,"test1",0.2);
  26. add_points(Mypoint0);
  27. Point Mypoint1(2,"test2",0.3);
  28. add_points(Mypoint1);
  29. cout<<"The length of vector is "<<cities.size()<<endl; 
  30. for(unsigned int i=0; i<cities.size();i++)
  31. {cout<<"id: "<<cities[i].id<<" context: "<<cities[i].context<<"  scroe: "<<cities[i].scroe<<endl;}
  32. }