c++ Input from text file help -
My test file contains data like this:
1 2 3 0 1, 2 3, 4, 0, 4, 3, 2, 0, 0
How do I separate on the basis of data, but I can also separate each section of data from zero.
ifstream data ("testData.txt"); String line, A, B; While (gateline (data, line)) {stringstream str (line); Ironingstream in; Ins.str (line); INS & gt; & Gt; One & gt; & Gt; B; Hold.push_back (a); Hold.push_back (b); }
How can I separate them from zero?
So the lines are important, and the list of zero-delimited numbers is also important? Try doing something like this:
std :: ifstream data ("testData.txt"); Std :: vector & lt; Integer & gt; Hold; Std :: string line; Std :: vector & lt; Std :: string & gt; Lines; While (std :: getline (data, line)) {lines.push_back (line); Std :: stringstream str (line); // Read an int and next character until one time (str.good ()) {int val; Four c; String & gt; & Gt; Val & gt; & Gt; C; If (val == 0) {do_something (hold); Hold.clear (); } And hold pius_back (val); }}
This is not very mistake-tolerant, but it works. It depends on a single character (a comma) after each last, leaving the last one on each row.
Comments
Post a Comment