二维vector容器读取txt坐标

Posted byteH

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二维vector容器读取txt坐标相关的知识,希望对你有一定的参考价值。

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坐标的主要内容,如果未能解决你的问题,请参考以下文章

C#语言读取txt行列数据

C#语言读取txt行列数据

C#语言读取txt行列数据

使用fstream将文件逐行读取到C++中的二维向量中[重复]

源码阅读 | OpenMesh读取文本格式stl的过程

Matlab读取txt文件并绘图(虚线图例坐标系大小)