- #1
Sdakouls
- 8
- 0
Hi,
I'm wondering if anyone would be able to help me with the following problem:
I have an input file in the form (values delimited by spaces):
0.0 0.0 0.0 Ga
0.5 0.5 0.5 As
1.0 1.0 1.0 In
.
.
.
and so on. (Basically it's a .txt containing x, y and z coordinates of atoms in a crystal lattice, along with the chemical symbol for the atom at a given lattice site.)
My aim is to try and write a program that would allow me to (for a given line of the file) to extract the data from this file so that I'd end up with (for line 2 in the above, for example):
x = 0.5
y = 0.5
z = 0.5
atom = As
where, x, y and z are doubles and atom is char* (or a string... I'm not fussy).
I'm familiar with the usual "reading an entire line of a file into a string" approach, but I'm not sure how to proceed in this instance since I need to take different parts of the line as different datatypes.
I've tried googling the problem and reading around, but I couldn't find anything hugely relevant.
Any help would be greatly appreciated.
I'm wondering if anyone would be able to help me with the following problem:
I have an input file in the form (values delimited by spaces):
0.0 0.0 0.0 Ga
0.5 0.5 0.5 As
1.0 1.0 1.0 In
.
.
.
and so on. (Basically it's a .txt containing x, y and z coordinates of atoms in a crystal lattice, along with the chemical symbol for the atom at a given lattice site.)
My aim is to try and write a program that would allow me to (for a given line of the file) to extract the data from this file so that I'd end up with (for line 2 in the above, for example):
x = 0.5
y = 0.5
z = 0.5
atom = As
where, x, y and z are doubles and atom is char* (or a string... I'm not fussy).
I'm familiar with the usual "reading an entire line of a file into a string" approach, but I'm not sure how to proceed in this instance since I need to take different parts of the line as different datatypes.
I've tried googling the problem and reading around, but I couldn't find anything hugely relevant.
Any help would be greatly appreciated.