Quote:
Originally Posted by HGClown
Ok, I'm using c++ and I need to get information from an input file, I'm fine with opening an input file and reading in the information but the problem I have is the input file is going to consists of lines of integers, I need to get the first four lines into 4 different arrays, use the data then move on untill all the data from the input file has been used. I wont know how many integers will be in each line, just that each line will be seperated by a carriage return.
Thanks,
HGClowns
|
One easy way would be to change your output file to include an integer at the beginning of the line giving you the number of integers on the line.
Then it becomes easy to loop through.
If you can't do that, it is much more difficult. You'll have to manually parse the line. I would read in each line a character at a time. You read in each number a digit at a time into a string until you reach a delimiter (a space, comma, or CR, depending on your format). When you reach that delimiter, convert the string you read in into a number, put that number into your array, lather, rinse repeat.
When you read the CR, then you know you've reached the end of the line (so to speak).
Good luck.