How to read a file into a struct?

honestly I'm just starting to learn c ++ .
I am currently a project for my university in which I developed most of the functions required, but i fail in the moment of opening the file and read it into an array.

the file is sth like this:

0110552018
0210011815
0409281947
0508151535
0609111801
0908411733
1110021725
2010091733
2510321921


the first 2 digits are the day. the next 4 digits are the time of entry, and the last 4 the time of exit of an employee.

So I want to read it into a struct like this


1
2
3
4
5
6
  struct employee{
                unsigned short int F_Day[2];
                unsigned short int F_hIn[4];
                unsigned short int F_hOut[4];
                };
Last edited on
Why did you choose to store the file in such an unusual format? Why do you use arrays of digits instead of actual numbers? Just separate the output by spaces and use actual numbers, and your problem is much easier to solve.
Last edited on
0110552018
0210011815
0409281947
0508151535
0609111801
0908411733
1110021725
2010091733
2510321921

That's a strange question.

1st, your title asks about assigning the numbers to a struct, here you say an array.

2nd, It truly depends on how you interpret the numbers. is each digit a separate number as in 0,1,1,0,5,5,2,0,1,8 ? so that you have 9 sets of 10 numbers, or is each line a number so that you have 9 numbers total? Whenever I see a large number that starts with zero I have to ask. I think it would be easier to use some type of delimiter. (space, comma, tab, character)

3rd Your struct has 3 variables, you have anywhere from 9 to 90 numbers to go in the struct.

If you "developed" the functions, you should be able to offer us more information to work with...

Topic archived. No new replies allowed.