Im trying to do a very simple thing, read numbers from a file using ifstream in C++. My input file called POSCAR
supercell
1.00000000000000
7.3287291297858630 0.0000000000000000 0.0000000000000000
0.0000000000000000 7.3287291297858630 0.0000000000000000
0.0000000000000000 0.0000000000000000 7.3287291297858630
Au Cu
1 31
My code to read these lines goes as follows:
ifstream poscar("POSCAR");
getline(poscar,skip); //Skipping comment first line
cout<<skip<<endl;
// Reading in the cubic cell coordinates
int factor;
poscar>>factor;
cout<<factor<<endl;
int nelm[10]; // number of elements in the alloy
float ax,ay,az,bx,by,bz,cx,cy,cz;
poscar>>unit_cell[0][0]>>unit_cell[0][1]>>unit_cell[0][2];
poscar>>unit_cell[1][0]>>unit_cell[1][1]>>unit_cell[1][2];
poscar>>unit_cell[2][0]>>unit_cell[2][1]>>unit_cell[2][2];
I get this error when I output what it has read:
supercell
1inf7.328730
0inf7.32873
7.3287291297858630
-142571760010922
Bus error
I dont understand what I am doing wrong. I thought the >> takes care of the tab spaces.