I have a file containing multiple lines. Numbers on each line are separated by ","
Each line is in set notation using "}".
The files look like:
{{1,2,3},{4,5,6},{7,8,9}}
{{10,11,12},{13,14,15},{16,17,18}}
Is there a way to read in only the numbers?
I was thinking of using get() to read the numbers until "," is encountered.
Then use ignore() to discard ",".
But anyway i think of using get() and ignore() will result in get reading a number as well as "}" assuming that i ignore the {{ at the start of the line.
i.e. it would eventually read 3} and then {4 etc.
I want to read the numbers into a 3D array but am stuck at reading only the numbers.
Or if you know the input format precisely you may use scanf. For example,
the first you line can be read as scanf("{{%d,%d,%d},{%d,%d,%d},{%d,%d,%d}}", &arr[0], &arr[1], ..., &arr[8]);
Or you can preliminary replace all non-number characters with spaces and than scanf or cin as usual