Getline from a txt file to a 3d array??

I have to read in 50 questions from a file , each that looks like this
--
What is the capital of Texas?
Kansas
Kentucky
Alaska
Austin

--

I have to output it to the user to look like this:
1. What is the capital of Texas?
A. Kansas
B. Kentucky
C. Alaska
D. Austin

--

Im having trouble using the getline function to store this data. What do you think about my struct and function to read the text in? I have to use a 2d or 3d array so I was thinking about rolling with the 3d:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

struct question{
string questions;
string answers;
}


//main would be here somewhere as well as code that doesnt have to do with the read in function//
question[50][5][150]; //array to capture 50 questions, 5 lines(q, a, a, a, a), and 150 chars to store getline //

void read_questions (string questions, string answers)
{
ifstream fin;
fin.open("question.txt")
    while (!fin.eof())
     {
       for (int i=0; i<SIZE; i++)
         {
       fin.getline(questions[i], answers[j]);
         }
	 
       fin.close();
	 
         return 0;
    }


im kinda lost right now any help or guidance is appreciated.
cheers
OK, first things first:

Line 9:
To declare an array, you need a type, name and size. In this case you have the type (question), but no name.
Furthermore, you shouldn't store the data in a 3D array of the question struct, since the question struct already stores the question and answers.

Line 2:
Except it doesn't , it only stores two strings - one for the question, and one for an answer, instead of one for the question and four for the answers (assuming there is always four possible answers to each question).
So back to line 9, just use a 1D array with 50 elements, each element on its own storing the 5 strings.

Line 19:
http://www.cplusplus.com/reference/string/getline/
getline takes two inputs, an istream and a string, the istream object being fin, your ifstream object. Also, you need to read 5 times, once for the question, and four times for the answer.

Line 15:
You're looping while fin is not at the end of the file, but within this loop you're reading SIZE times (presumably 50, right?) which would in itself read the entire file within one while loop, so it's redundent. It would be better to put the loop around the getline, and check instead to see if fin is good (while(fin.good){...}).

Line 24:
read_questions(...) returns void, not int, so you don't return a value, you just call return to exit the function. This is also another reason why your while loop is redundent - after reading SIZE times, the function returns, and never loops through the while again.

If I'm unclear about any of this, please tell me and I'll try to be more clear.
Topic archived. No new replies allowed.