Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从文本文件中读取矩阵,使用C++中的一列数_C++ - Fatal编程技术网

从文本文件中读取矩阵,使用C++中的一列数

从文本文件中读取矩阵,使用C++中的一列数,c++,C++,我是初学者 我正在使用CORSIKA软件。cosika的输出是8列或7列的文本文件和2000多行矩阵。 这个矩阵的数组是科学记数法中的数字,就像衰减图像一样 2.11285E+05 2.00000E+01 1.30714E+05 7.35000E+00 1.00000E+00 1.10000E+04 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0.0

我是初学者 我正在使用CORSIKA软件。cosika的输出是8列或7列的文本文件和2000多行矩阵。 这个矩阵的数组是科学记数法中的数字,就像衰减图像一样

2.11285E+05  2.00000E+01  1.30714E+05  7.35000E+00  1.00000E+00  1.10000E+04  0.00000E+00
0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00  0.00000E+00
0.00000E+00 -2.70000E+00  1.00000E+03  1.00000E+03  1.00000E+00  1.00000E+00  3.00000E-01
3.00000E-01  3.00000E-03  3.00000E-03  6.37132E+08  6.00000E+05  2.00000E+06  0.00000E+00
0.00000E+00  4.58060E-02  5.73090E-01  5.28304E-02  2.50000E+00  2.07000E+00  8.20000E+00
1.00000E-01  0.00000E+00  0.00000E+00  1.00002E+00  9.67266E-03  1.00000E+00  5.75129E-04
0.00000E+00  0.00000E+00  3.77000E+01  1.53287E-04  9.38642E+00  2.00000E-03  2.99792E+10
我想读取第7列中的数据,并在一列中计算一些参数,如平均值、最大值、最小值

我有这个代码来读取和显示文本文件,但我不知道如何使用数字和计算一些参数

#include<iostream.h>        
#include<stdio.h>
#include<conio.h>

int main()
{
    FILE *k;
    char c;
    k = fopen("c:\\fff.txt", "r");
    c = getc(k);
    while(c != EOF)
    {
         cout << c;
         c = getc(k);
    }
    getch();
    fclose(k);
    return 0;
}
请帮帮我。 谢谢

试试这个:

#include <iostream>
#include <string>
#include <sstream>

int main()
{
    std::string line;
    std::istringstream iss;

    while (std::getline(file >> std::ws, line))
    {
        float f;

        iss.str(line);
        while (iss >> f)
            ;

        // f is equal to the 7th row by this line
    }
}

根据您的需要,F可以是while循环的范围内的或其他的。

如果您使用C++,则使用FSFET更容易。看:举个例子,你有没有得到偷你标签钥匙的人的驾照?