Link to home
Start Free TrialLog in
Avatar of derekpapesch
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?
ASKER CERTIFIED SOLUTION
Avatar of Mustak_Shaikh
Mustak_Shaikh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of efn
efn

You should have a class that stores the data for one question and an array or vector of objects of that class.

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
Avatar of derekpapesch

ASKER

Thanks Mustak_Shaikh,

That's brilliant.  It's working.