string help

Hi there, I've been trying to create a model loader and I have somewhat succeeded but I need these 2 tools to succeed. The first one is say I have a file that looks like this: 1. I first find end_header and store it's line # into a variable. Now where I need help is I want basically what i want to do is read all of the information below and put it into a string. So is there a function or a way i could use that'll will read all the information from lines x(11 in this case) all the way to line x(41) in this one). Then my second problem is I want to separate each coordinate:
let's use this line as an example:
 
1.000000 0.999999 1.000000

I want to split the 1.000000, the 0.999999 and the 1.0000000. What I was thinking of doing was finding a way to read from the first character(1 in this case) all the way till it finds a space a.k.a the end of that coordinate and then after skip 1 character and repeat the previous step.



Thank you for your help it would mean a lot if someone can help me solve these 2 problems

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
property float y
property float z
element face 6
property list uchar uint vertex_indices
end_header
1.000000 1.000000 -1.000000 
1.000000 -1.000000 -1.000000 
-1.000000 -1.000000 -1.000000 
-1.000000 1.000000 -1.000000 
1.000000 0.999999 1.000000 
-1.000000 1.000000 1.000000 
-1.000000 -1.000000 1.000000 
0.999999 -1.000001 1.000000 
1.000000 1.000000 -1.000000 
1.000000 0.999999 1.000000 
0.999999 -1.000001 1.000000 
1.000000 -1.000000 -1.000000 
1.000000 -1.000000 -1.000000 
0.999999 -1.000001 1.000000 
-1.000000 -1.000000 1.000000 
-1.000000 -1.000000 -1.000000 
-1.000000 -1.000000 -1.000000 
-1.000000 -1.000000 1.000000 
-1.000000 1.000000 1.000000 
-1.000000 1.000000 -1.000000 
1.000000 0.999999 1.000000 
1.000000 1.000000 -1.000000 
-1.000000 1.000000 -1.000000 
-1.000000 1.000000 1.000000 
4 0 1 2 3 
4 4 5 6 7 
4 8 9 10 11 
4 12 13 14 15 
4 16 17 18 19 
4 20 21 22 23 
Last edited on
lookt at the iostream:

http://www.cplusplus.com/reference/istream/iostream/?kw=iostream

the operator << and >> are doing what you want.


use fstream to read a file with this operators:

http://www.cplusplus.com/reference/fstream/fstream/?kw=fstream
I used scanf instead !
Topic archived. No new replies allowed.