0

对于一个项目,我想读取不同数组中的文本文件的列。首先,我在一个 2D 字符串数组中读取文件,并将该数组拆分为不同的intfloat1D 数组。但是当我使用or方法将数字转换为intof时,我遇到了分段错误。有人有其他解决方案吗?floatatofatoi

void Tftdiag::readFile(std::string file)
{
   string testline;
   char tab2[1024];
   strcpy(tab2, file.c_str());
   ifstream Test( tab2 );
if (!Test)
{
    cout << "There was an error opening the file.\n";
}
//store words in array
int x=0,y=0;
while( Test>>testline )
{
    word[y][x]=testline;
    x++;
    if (testline=="")
    y++;
}
//output whole array with array position numbers for each entry
cout<<"Array contents:\n";
for (int y=0;y<50;y++)
{
    for (int x=0;x<6;x++)
    cout<<word[y][x]<<"("<<y<<","<<x<<")"<<endl;
}
for(int i=0; i<50; i++) {

   voltage[i]= atof("0.5".c_str());
   //currentArray[i]= atof(word[50][1].c_str());
   //lux[i]= ::atof(word[50][2].c_str());
   //red[i]= atoi(word[50][3].c_str());
   //green[i]= atoi(word[50][3].c_str());
   //blue[i]= atoi(word[50][3].c_str());
}
}
4

1 回答 1

0

我已经运行了一个调试器,并且在索引 0 处出现错误,其值为“7,701”,并带有以下行。

电压[i]= atof(字[50][0].c_str());

于 2016-03-22T15:51:29.580 回答