-
Reading Data
I am working on a script to write a file that i want to import in my game im writeing.
Im laying out the info like so
Name
Short Name
1 1 1 1 1 0 0 0 0 1 0 0
5.0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
0 0 0 0 0 0 0 0 0 0
0
Will i have problems reading this, or is it easy to just read in one value at a time? Im concerned about when some of the values become double or tripple digit, Will I have a hard time sorting them out? Should i make everything on a seperate line? Im just trying to plany ahead, and dont know what I need to account for.
-
You should be able to read/write the file as presented using single data read/writes without much trouble. If the number of variables per line is constant it will be easier, but can be done relatively straightforward even if there is a variable number of values on a given line in a given record.
>> to read in first line
ignore() to remove new line char
getline() to read in second line
loop with >> to read in ints in third line
loop with >> to read in doubles in fourth line
loop with >> to read in ints in fifth line
>> to read in int in last line.
If there is a standard size to the strings and a standard quantity to the various numbers on the various lines you could even create a struct/class to hold all the data and read/write with a single call using read()/write() althought the file will probably be in binary and therefore very difficult for you to read, although the computer will have no problem.