Can I read a file like this into an Array?

This is the txt file we were given.

Barney Jones 95 83 92 85 87 85 29
Sandra King 99 97 92 91 92 95 32
Josh Harding 0 0 0 0 31 37 30

Can I read strings and ints into one array? This was a homework assignment but it was due last Friday. I need to learn this. I got a 0 on the assignment but I still need to learn it.
You can read in an array element the same way you'd read in other variable.
You'd have to write a loop to fill the array reading each time on a different array element
I have to read the file into an array somehow. It will have string and int types and I don't know if that can be done.
I think I understand what you want to do. The short answer is no, you can't store values of different types in a single array. The long answer is that you can do what you want using arrays of structures. Define a structure containing a string and an array of 7 ints. And then declare an array of 3 such structures.

I believe you will find these links useful:
http://cplusplus.com/doc/tutorial/structures/
http://cplusplus.com/doc/tutorial/arrays/
Last edited on
Topic archived. No new replies allowed.