Read a file scientific notation into 2D array in C++

I have a question on how to read a file with scientific notation into 2D array.

Let's say I have a file with a name "test.txt" and its contents:
1.0e-5 0 0.644e-21
3.0 14 253.0e10

Each number is separated by spaces. Could you tell me how I could load the numbers into 2D array?

It would be greatly appreciate if you would make a sample code.
Read line in file, count spaces, strtok(...), allocate memory for array, load using loop.
So far, I wrote the following code, but I got errors. How could I fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

void Read_Sci_Notation(double * array[], int i){
    ifstream file;
    file.open("txt.txt");
    //double array[i][i];
    double q;
    while(!file.eof()){
        file >> q;
	//cout << q << endl;
	int j, k;
	for(j = 0; j <=i; j++){
	for(k = 0; k <=i; k++){
	array[j][k]->push_back(q);
	}
	}
	}
}

int main(){
    int mat_size = 2;
    double array[mat_size][mat_size];


    Read_Sci_Notation(&array,mat_size);    

    /*check*/
    cout << array[0] << "test" << endl;

}
Topic archived. No new replies allowed.