I have a text file, the contents are
Point1, [5, 6]
Line2, [1, 2, 3], [-5, 55, 33]
Point2, [5, 3, 1]
Line1, [1, 2], [5, 7]
I will do comparisions, like the first variable (Point1, Line2, Point2, Line1)
If it is point1, it will be stored into point 1 array, and 5 being set as x, and y being set as 6.
How do I set the delimter to commas and also the ‘[‘ and ‘]’. I just need the variable Point1, 5 and 6 to store them accordingly.
I would solve this problem the simplest way possible – read the file using getline and then replace all the occurances of
,,[and]with spaces. Then you can read all the input usingstd::istringstreamfrom<sstream>. You could also use regular expressions(if you use boost or c++-11), but I believe what I suggest should do the job.EDIT: here is an example how to do what I suggest. I will only show you how to input points, to handle lines as well you will have to add an if statement based on name.
Also you can use
replace_iffrom<algorithm>to replace the symbols, but I decided it will be easier for you to understand this solution.