gpt4 book ai didi

c++ - 从坐标 vector 中提取坐标并保存到文件

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:43 25 4
gpt4 key购买 nike

我有一个 vector ,其中包含一个列表坐标 ...x1,y1 ; x2,y2....xn,yn

我正在尝试提取作为坐标的每个单独元素,然后将它们保存到文件中,作为一个很好的描绘坐标对,可以很容易地阅读。或者我最好保存它们以便我可以在 excel 等中绘制一些东西(作为 x 和 y 值的列)。

我的原始 vector 大小是 31,最初构造为

vector<vector<Point> > myvector( previous vector.size() );

最佳答案

在 C++ 中写入 Excel 文件很容易。您可以按如下方式进行。

      #include<iostream>
#include<fstream>
#include<vector>

using namespace std;

vector<Point> myVec;

void main()
{
ofstream fout("C:/output.xls");

for(unsigned int i=0; i<myVec.Size(); i++)
{
int x = myVec[i].x;
int y = myVec[i].y;

fout<<x; //Write value of x in first column

fout<<"\t"; //Jump to next column

fout<<y; //Write value of y in next column

fout<<endl; //Jump to first column of next row
}

fout.close();
}

使用 Microsoft Excel 打开输出文件时,可能会显示警告。你可以忽略它。

关于c++ - 从坐标 vector 中提取坐标并保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12724345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com