C++ 从制表符分隔的文本文件中读取单列

C++ 从制表符分隔的文本文件中读取单列,c++,qt,C++,Qt,下面是制表符分隔文件的一个示例(一部分),我想从中提取用于单独阐述的列: 0.0000000000000000e+000 -2.2562500000000000e+001 -2.0625000074505806e-001 -1.0000000149011612e-001 -3.0625000223517418e-001 9.9999999392252903e-009 -2.5687500000000000e+001 -2.062500007450

下面是制表符分隔文件的一个示例(一部分),我想从中提取用于单独阐述的列:

 0.0000000000000000e+000     -2.2562500000000000e+001    -2.0625000074505806e-001    -1.0000000149011612e-001    -3.0625000223517418e-001   
  9.9999999392252903e-009    -2.5687500000000000e+001    -2.0625000074505806e-001    -1.0000000149011612e-001    -3.0625000223517418e-001   
  1.9999999878450581e-008    -3.1937500000000000e+001    -3.6250000074505806e-001     5.6249998509883881e-002    -3.0625000223517418e-001   
  2.9999999817675871e-008    -3.3500000000000000e+001    -3.6250000074505806e-001     5.6249998509883881e-002    -3.0625000223517418e-001   
  3.9999999756901161e-008    -3.1937500000000000e+001    -2.0625000074505806e-001     5.6249998509883881e-002    -1.5000000223517418e-001   
  4.9999999696126451e-008    -3.0375000000000000e+001     1.0624999925494194e-001     5.6249998509883881e-002     1.6249999776482582e-001   
  5.9999999635351742e-008    -2.4125000000000000e+001     1.0624999925494194e-001    -1.0000000149011612e-001     6.2499977648258209e-003   
  6.9999999574577032e-008    -1.9437500000000000e+001     1.0624999925494194e-001    -1.0000000149011612e-001     6.2499977648258209e-003   
  7.9999999513802322e-008    -1.9437500000000000e+001     1.0624999925494194e-001    -2.5625000149011612e-001    -1.5000000223517418e-001   
  8.9999999453027613e-008    -1.9437500000000000e+001     2.6249999925494194e-001    -2.5625000149011612e-001     6.2499977648258209e-003   
  9.9999999392252903e-008    -1.1625000000000000e+001     2.6249999925494194e-001    -1.0000000149011612e-001     1.6249999776482582e-001   
  1.0999999933147819e-007     4.0000000000000000e+000     2.6249999925494194e-001    -1.0000000149011612e-001     1.6249999776482582e-001   
  1.1999999927070348e-007     1.1812500000000000e+001     1.0624999925494194e-001    -1.0000000149011612e-001     6.2499977648258209e-003   
  1.2999999920992877e-007     8.6875000000000000e+000     1.0624999925494194e-001    -2.5625000149011612e-001    -1.5000000223517418e-001   
  1.3999999914915406e-007     8.6875000000000000e+000    -5.0000000745058060e-002     5.6249998509883881e-002     6.2499977648258209e-003   
  1.4999999908837935e-007     1.3375000000000000e+001    -5.0000000745058060e-002    -1.0000000149011612e-001    -1.5000000223517418e-001   
  1.5999999902760464e-007     1.1812500000000000e+001    -5.0000000745058060e-002    -1.0000000149011612e-001    -1.5000000223517418e-001   
  1.6999999896682993e-007     8.6875000000000000e+000    -2.0625000074505806e-001     5.6249998509883881e-002    -1.5000000223517418e-001   
  1.7999999890605523e-007     8.6875000000000000e+000    -2.0625000074505806e-001     2.1249999850988388e-001     6.2499977648258209e-003   
  1.8999999884528052e-007     1.3375000000000000e+001    -3.6250000074505806e-001     5.6249998509883881e-002    -3.0625000223517418e-001   
  1.9999999878450581e-007     8.6875000000000000e+000    -3.6250000074505806e-001     5.6249998509883881e-002    -3.0625000223517418e-001
从这些数据中,我想提取第二列和第四列。 做这件事的简单方法(代码)是什么

提前感谢:)

这是打开文件的部分(qt框架):

这是读取列的代码:

void MainWindow::on_LoadVoltageButton_clicked()
{   
    float  col1[74],col2[74],col3[74],col4[74],col5[74];
    int num=0;
    string Load;
    ifstream dataAgie;
    dataAgie.open("C:/Users/Marco/Desktop/Segmentazione+GUI_GFAC/20130909_LT25A_E21_H20_1/data_t_U_I_test.txt");
    if(dataAgie.fail()) // checks to see if file opended 
    { 
      QMessageBox::information(this,tr("STOP"),tr("Error with loading"));
      //this->close();
      } 
    while(getline(dataAgie,Load)) // reads file to end of *file*, not line
      {  
         istringstream is(Load);
         double P;
         double Q;
         int n=0;
         is >> P >> Q;

      } 

}
向量列1;
向量列2;
向量列3;
浮动温度1;
浮动温度2;
浮动temp3;
ifstream文件(“编号”);
而((文件>>临时1)&&(文件>>临时2)&&(文件>>临时3))
{
第1列。推回(temp1);
第2列。向后推(temp2);
第3列。向后推(temp3);
}

这不是最快的解决方案,但又短又简单。

使用我制作的列迭代器,您只需执行以下操作:

intmain(){
自动c2=读取列(is,2);
自动c4=读取列(is,4)
}
您甚至可以在地图中保留这些列,以便于访问:

std::映射列;
柱.安放(标准::make_pair(2,c2));
柱.安放(std::make_pair(4,c4));

您是否已经尝试过一些方法?请展示一些解决问题的方法,如果您遇到了特定问题,请返回。我认为最好的方法是解析文件并创建一个带有浮点/双精度值的二维数组,然后通过索引到二维数组中来访问列。@anderas是的……我尝试了几种方法,最后一种方法是我有一些问题要识别小数前的“点”。“西蒙,这是一种可能性……但是我的Fyle是非常巨大的:200兆字节的记录。”我尝试了几种方法。
void MainWindow::on_LoadVoltageButton_clicked()
{   
    float  col1[74],col2[74],col3[74],col4[74],col5[74];
    int num=0;
    string Load;
    ifstream dataAgie;
    dataAgie.open("C:/Users/Marco/Desktop/Segmentazione+GUI_GFAC/20130909_LT25A_E21_H20_1/data_t_U_I_test.txt");
    if(dataAgie.fail()) // checks to see if file opended 
    { 
      QMessageBox::information(this,tr("STOP"),tr("Error with loading"));
      //this->close();
      } 
    while(getline(dataAgie,Load)) // reads file to end of *file*, not line
      {  
         istringstream is(Load);
         double P;
         double Q;
         int n=0;
         is >> P >> Q;

      } 

}
vector<float> column1;
vector<float> column2;
vector<float> column3;
float temp1;
float temp2;
float temp3;

ifstream file("numbers");

while ((file >> temp1) && (file >> temp2) && (file >> temp3))
{
  column1.push_back(temp1);
  column2.push_back(temp2);
  column3.push_back(temp3);
}