derekpapesch
asked on
Storing string arrays?
I have an a 1000 rows of data stored in a file something like this:
question 1 text q1 answer q1 difficulty
question 2 text q2 answer q2 difficulty
... (998 more)
After loading the data, where should I put this data? I would like to put it in a multidimensional array, but am new to C++ data structures, and not sure if this is the best option.
What would be the best way to store this data in C++ so I can rapidly pull up a random question?
question 1 text q1 answer q1 difficulty
question 2 text q2 answer q2 difficulty
... (998 more)
After loading the data, where should I put this data? I would like to put it in a multidimensional array, but am new to C++ data structures, and not sure if this is the best option.
What would be the best way to store this data in C++ so I can rapidly pull up a random question?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Mustak_Shaikh,
That's brilliant. It's working.
That's brilliant. It's working.
If you are sure that there will always be 1000 questions, you can use an array. A vector works like an array, but gives you more flexibility with its size--it's like an array that can grow as needed.
Mustak_Shaikh was on the right track recommending a structure or class, but you might want to represent the difficulty as a number rather than a string and you probably don't want all the members to be private. You could also consider using string objects rather than character arrays. As with vectors, string objects give you more flexibility with the size.
--efn