vector<vector<int> >vt; //变量的定义
vt.push_back(vector<int>(10,1)); //用1行10列的向量初始化,初始值为1
vt.push_back(vector<int>(10,2));
for(vector<vector<int> >::iterator it=vt.begin();it!=vt.end();it++) //判断外层循环
{
for(vector<int >::iterator it1=it->begin();it1!=it->end();it1++) //判断内层循环
cout<<*it1<<" ";
cout<<endl;
}
vector 例子:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
class Point
{
int obj_id;
string des;
float x, y;
static int count;
public:
Point(){}
Point(int a,float c, float d, string e) :obj_id(a), x(c), y(d),des(e){ count++; }
static int GetCount(){ return count; }
bool operator<(const Point &p){ return (x < p.x || (x == p.x && y < p.y)); }
float Getx() { return x; }
float Gety() { return y; }
string Getdes() { return des;}
};
int Point::count=0;
bool lessmark( Point &p1, Point &p2)
{
return p1 < p2;
}
void main()
{
fstream p_file("f:/point.txt", ios::in );
if (p_file.fail())
{
cout << "p_file文件打开失败";
exit(0);
}
vector<Point> point;
int a;
float x1, y1 ,x2;
string des;
while (!p_file.eof())
{
p_file >> a >> x2 >> x1 >> y1 >> des;
cout<< a <<" "<<x2<<" "<<x1<<" "<<y1<<" "<<des<<endl;
Point p(a, x1, y1, des);
point.push_back(p);
}
p_file.close();
vector<Point>::iterator itp = point.begin();
ofstream p2_file("f:/point2.txt");
sort(point.begin(), point.end(),lessmark );
for (; itp != point.end(); itp++)
{
cout<<(*itp).Getx()<<" "<<(*itp).Gety()<<" " << (*itp).Getdes()<<endl;
}
p2_file.close();
}