gpt4 book ai didi

c++ - 将 .csv 文件转换为 C++ 算法中的结构

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:24:30 25 4
gpt4 key购买 nike

我想将 .csv 文件读入 C++ 代码,然后将文本数据转换为结构。我可以编写算法来读取 .csv 文件,但如何将其保存到结构中... .. csv 文件中的数据在 excel 单元格中,第一列包含纬度,第二列包含经度,第三列包含分支代码,第四列包含地址,并且有 7000 行包含不同的位置和地址..我需要保存这些在C++算法中变成一个结构

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {
string line;
ofstream myfile;
myfile.open("burgerking.csv");
if(myfile.is_open()){
cout<<"The file is open"<<endl;
while (getline(myfile,line)) {
cout << line << '\n';
}
}
myfile.close();
system("PAUSE");
return 0;
}

最佳答案

存储互连结构的一种(好)方法是使用索引:

你不能/不应该写入文件 内存地址 0x12345678 的结构,但你可以写入 这是结构 181,它的第一个引用转到结构 912,它的第二个引用转到到...

它可以高效地完成:有一个 hashmap 将结构指针映射到您为它们选择的索引,每次您要写一个指针时,您都会写索引。

关于c++ - 将 .csv 文件转换为 C++ 算法中的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20567582/

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