file i/o

Hi All,
I am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:

1
2
3
4
3
10110101
11111111
10101010


The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.

I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is I have no idea how to say "ok the first line says 3, so now I have to convert the next 3 lines"

I am assuming it is just a simple loop that I am missing, but if anyone could help out that would be wonderful!

Thanks
Yes, it is exactly a loop that you will need. Read in the first number, then loop that many times, reading in the strings and converting them.
@Zhuge,
Could you help out with differentiating between the first line and the remaining lines?
well he's basically told you.
the first line will tell you how many more lines you have to iterate down e.g. iterate the next 3 and treat them as binary. Then you know the line after this will be another integer, and so on.
What do you mean by differentiate? Just read into a variable called, say, number_of_lines, then make a loop that reads into a vector or some other container. The lines will be differentiated by the variables they are in; I'm not sure if I'm understanding your confusion.
Topic archived. No new replies allowed.