c++ - How do I get my program to recognize and sort the different variable types from a .txt file? -


fairly new c++ (and programming in general). i'm trying write out program read following input.txt:

10 4 6 15 6 b 20 10 b 12 8 54 12 b 64 9 73 30 80 10 b 99 15 

as shown, there's combination of int variables char (a , b). using ifstream, program recognizes first 3 int (10, 4, 6) fine. however, i'm trying figure out way sort out remaining variables specific arrays.

for instance, want recognize every time there's 'a', first int after 'a' goes 1 array , following int goes array. in case have arrays [15,54,73,80] , [6,12,30,10].

please note input.txt not set , need able have read file different number of a's , b's.

there number of ways solve problem, including writing boost::spirit grammar, wouldn't recommend new c++.

instead, i'll suggest direct approach, involves if statement:

- instead of streaming int, stream string. - each string (word), check if word or b,  if add char container.  otherwise call stoi , add int container. 

Comments