chapter4-1.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:chapter4-1.cpp
- #include <iostream.h>
- #include <iostream>
- #include <vector>
- #include <string>
- class Point
- {
- public:
- int id;
- char *context;
- double scroe;
- Point(int i, char *j,double d)
- { id=i;
- context=j;
- scroe=d;
- }
- Point(){};
- };
- std::vector<Point> cities;
- void add_points(Point sentinel){ cities.push_back(sentinel);}
- void main()
- {
- Point Mypoint(0,"test0",0.1);
- add_points(Mypoint);
- Point Mypoint0(1,"test1",0.2);
- add_points(Mypoint0);
- Point Mypoint1(2,"test2",0.3);
- add_points(Mypoint1);
- cout<<"The length of vector is "<<cities.size()<<endl;
- for(unsigned int i=0; i<cities.size();i++)
- {cout<<"id: "<<cities[i].id<<" context: "<<cities[i].context<<" scroe: "<<cities[i].scroe<<endl;}
- }