for my CS class.. cant use vectors! Ive searched everywhere for some information on how to read in lines of string from a txt into a two-d or 3d array and i cant find ANyTHING. i need some help please.
reading in a text file that looks like this:
- what is the capital of texas?
- austin
- kansas
- harlingen
- dupont
- blankline
- blankline
- what is the capital of maine?
- etc
- etc
so its blocks: 1 question 4 answers, two empty lines, repeat.
my array to store 50 questions, each with 5 lines
string questions[50][5];
my function to read in txt file into array
void read_questions(string[], string[])
{
ifstream.fin;
fin.open("questions.txt")
while (!fin.eof{}}
fin.getline([i][j];
}
i know i am far off but if you can point me to some references i would appreciate. ive looked through many resources and googled many times but cant find any examples close to mine atall. i asked at another site but they keep telling me to use vectors but we cant we have to use a 2d or 3d array
That line declares an array of an array of
strings. That’s a good enough start.To read each line in, you’ll need:
The nested loops are easy:
Picking an input function is pretty easy, too. You’ll want to use
std::getline(std::istream&, std::string&).