gpt4 book ai didi

c++ - 从大尺寸的 .csv 文件转换为二维数组

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:55 24 4
gpt4 key购买 nike

我将 HOG 特征存储在 .csv 文件中,该文件的尺寸为 1967 X 2916。当我尝试将值存储在一个简单的二维数组中时,我无法执行该过程。但可以运行到 88 X 2916 的尺寸。你能告诉我这背后的原因吗? 我使用的以 .csv 格式存储的功能可以在这里找到 https://www.dropbox.com/s/j04echzhwjwhgjk/data.csv?dl=0

代码看起来像这样。

 #include<fstream>
#include <sstream>

using namespace std;

int main(){

float dataset[1967][2916];
ifstream file("data.csv");

for(int row = 0; row < 1967; ++row)
{
std::string line;
std::getline(file, line);
if ( !file.good() )
break;

std::stringstream iss(line);

for (int col = 0; col < 2916; ++col)
{
std::string val;
std::getline(iss, val, ',');
if ( !iss.good() )
break;

std::stringstream convertor(val);
convertor >> dataset[row][col];
}
}

for(int p=0;p<1967;++p)
{
cout<<endl;
for(int q=0;q<2916;++q)
{
cout<<dataset[p][q]<<"\t";
}
}

return 0;

最佳答案

这很可能是堆栈溢出,这很讽刺,考虑到你发布这个的位置。堆栈通常限制在 1-2 MB 左右(这可以通过编程方式更改)。

您可以通过将 dataset 设为全局来进行快速测试,这会将其移出堆栈:

float dataset[1967][2916];
int main(){
...

如果测试成功,你应该把 dataset 放在堆上。

相关:C/C++ maximum stack size of program

关于c++ - 从大尺寸的 .csv 文件转换为二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27374951/

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