码迷,mamicode.com
首页 > 其他好文 > 详细

二维vector容器读取txt坐标

时间:2018-01-29 18:18:56      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:body   out   post   oca   temp   cat   pos   文件   vector   

template <class vector>
struct HeadLocation{
	vector x;
	vector y;
};

vector<HeadLocation<int> > gt_loc_;  //二维vector容器

void ReadLocationFromTextFile(const string filename) {
	cout << "Opening file " << filename << endl;
	ifstream infile(filename.c_str());
	if (!infile){ printf("不存在此文本文件!"); };
	int num_crowd;
	infile >> num_crowd;
	if (num_crowd <= 0){ cout << "Number of crowd must be positive!\n"; };
	gt_loc_.clear(); //size = 0, capicity =?
	gt_loc_.resize(num_crowd); //size = num_crowd(行)

	for (int i = 0; i < num_crowd; i++) {
		/*HeadLocation<float> location_t;
		HeadLocation<int> location(location_t.begin(), location_t.end());*/
		HeadLocation<int> location;
		infile >> location.x >> location.y;

		for (int j = 0; j < 3; ++j) {
			location.x = (location.x - 1) / 2;
			location.y = (location.y - 1) / 2;
		}
		gt_loc_[i] = location;
	}
	infile.close(); // 关闭文件
}

  

二维vector容器读取txt坐标

标签:body   out   post   oca   temp   cat   pos   文件   vector   

原文地址:https://www.cnblogs.com/byteHuang/p/8378657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!