Input tags separator

Mar 22, 2009 at 1:39am
I've written the following loop that stores each line of a file into the row of a 2D array, item by item (i.e. word by word).

Now it happens that the items separators are not blank spaces anylonger but are semicolons. End of line is still \n.

How can I change the loop accordingly?

1
2
3
4
5
6
7
8
9
10
        r=0;
        while (getline(inp_file, line)) {
                istringstream streamline (line);
                c=0;
                while (streamline >> item) {
                        matrix[r][c] = item;
                        ++c;
                }
                ++r;
        }
Mar 22, 2009 at 7:35am
You can try with getline using ';' as delimiter instead of the >> operator

http://www.cplusplus.com/reference/string/getline.html
Mar 23, 2009 at 1:35am
Bazzy, Thanks.

I knew about that but it did not seem appropriate for this case. Instead, thinking it through, it is very appropriate and I made it working fine.

Thanks!

P.S. I do not want that you guys think that I'm posting here without doing due diligence (i.e. serching all over) before. This forum for me is the very last resort.
Mar 23, 2009 at 2:46am
Not a problem...the worst people are those who go:

"OMG HW PROBLEM! SOLVE PLZ!!!!"
Topic archived. No new replies allowed.