I am trying to read the data from a text file and store it into array. I need it for solving FEM problem. Let's say my text file is as follows:
node: 1,2,3,4,5,6,7,8,9,10
x: 4,4,3.75,3.76773151,3,3.59192947,4,3.5,3.55115372,3.375, 3.71330586
y: 3,275,3,2.65921885,2.79192947,2.5,3,2.55115372,2.78349365,2.36222989
z: 0,0,0,0,0,0,0,0,0,0
I want to store this data from text file into a 10*4 matrix (myarray[10][4]
). Also I need to store each column of this array into a vector. Let's say my vectors are:
double x[10];
double y[10];
double z[10];
for (int i = 0; i < 10; i++)
{
x[i] = myarray[i][1];
y[i] = myarray[i][2];
z[i] = myarray[i][3];
}
I wrote the code like this:
int main()
{
string line;
string coordinate[10][4];
ifstream mesh("mesh.txt");
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 4; ++j)
{
if (getline(mesh, line, ';'))
{
coordinate[i][j] = line;
cout << coordinate[i][j] << endl;
cout << "mesh : " << line[0] << endl;
}
}
}
mesh.close();
}
Now my problem is when I want to put the each column of coordinate into a vector I get this error:
no suitable conversion function from string to double exist
I don't understand this error, and need help fixing it.