输入数据"data.txt"
数据格式如下:
123 234
123 34
131 546
123 767
程序代码
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
ifstream fin;
vector<Point2d> pointset;
Point2d pts;
double temp_x = 0, temp_y = 0;
fin.open("data.txt");
//!fin.eof() 用来控制什么时候读取终止
for (int i = 0; !fin.eof(); i++)
{
//读取txt文件的坐标值
fin >> temp_x >> temp_y;
pts.x = temp_x;
pts.y = temp_y;
pointset.push_back(pts);
}
for (int i = 0; i < pointset.size(); i++)
{
cout << "(" << pointset.at(i).x << " , " << pointset.at(i).y << ")" << endl;
}
fin.close();
system("pause");
}
输出结果
转载自:
博主:rishown
博文地址:https://blog.csdn.net/rishown/article/details/79738560
来源:CSDN