array

I'm trying to read a file with unknown number of rows and 4 columns of string and int into a array. I'm not really sure how that would work... could someone give me an idea of how to do it, or an example? Thanks.
Can you show us the contents of your input file?
Hi lado,

Here is an idea :

1- create a class Row with 4 properties (string). Each object of this class is a row.
2 - in the core of the main fonction, create a list<Row*>
3 - read the file line by line and push a new object in the list for each line in the file.

It is not a array, but a list of Row.
If You absolutly need to have an array, I would read the file a first time to get its size, then I would dim a array and fill it in a loop.

In both cases, have a look at this to read the lines and split the data http://www.cplusplus.com/reference/cstdio/vfscanf/

Hope that helps
Last edited on
Why are you starting a new thread for this?

You were given a solution here:
http://www.cplusplus.com/forum/beginner/198017/#msg949144

In that example, I used 100 as the maximum number of rows. If that is not enough you can easily change the MAX_ROWS constant. If you don't know the maximum number of rows, then use a std::vector.
Last edited on
Topic archived. No new replies allowed.