File Input, how to get number of items?
I have a file to input into one of my C++ programs. I can get input and all that, but I was wondering if it is possible to take the file and get the number of items (each item is seperated by whitespace) and put that into a variable. The variable and the data in the array is all of type int.
THank you. |
Do you mean without reading the data? If the data is of fixed size, you could calculate the number of items from the size. If the data ends with a newline, then divide the size by the item size +1.
Or you could precede the file with metadata containing the number of items. Another option is to read up to a sentinel and have the count after the sentinel. Then you could position the file pointer at an offset from the end of the file and read just the count. |
All times are GMT -5. The time now is 03:57 AM. |