I'm a total newbie to C++ and programming in general, so please bear with me while I try and explain myself.
I need to input information into a structure from a .txt file. The information in the text file is as so:
Joe
11 12 13
Sally
10 11 12
...
Pretty much the structure needs to contain the name, a (in case 1, 11), b(in case 1, 12), and c(in case 1, 13). I'm looking to do this recursively, so that it goes through every name and a, b, and c. I'm really at a loss for where to begin, and I'm really just looking for some guidance.
I was thinking maybe putting the names into one 2D char array and a, b, and c into another 3D char array? But I'm not really sure how to do that, or what purpose that would have.
Thanks for any and all help!
Okay, so here's what I've got. It's at it's very early stages, but it's something.
#include<iostream>
#include<fstream>
using namespace std;
const int max_names=100, a=100, b=100, c=100;
char names[max_names];
int num1[a];
int num2[b];
int num3[c];
int main()
{
ifstream inFile;
inFile.open("data.txt");
while(!inFile.eof())
{
for(int i=0; i<max_names; i++)
{
inFile>>names[i]>>num1[i]>>num2[i]>>num3[i];
}
}
return 0;
}
struct Person
{
char names[max_names];
int num1[a];
int num2[b];
int num3[c];
}
EDIT: While I'd like to not use recursion/structs, I have to for class. Also, upon further looking at what I'm supposed to do, I need to create an array of structs. Is this hard to do? I'm working on what I think is some code right now, but I'm probably going to be totally off.
I need to use the struct identifier. Like "struct Person"
EDIT 2: Yes, recursion, yes structs, no iteration, no class. It has to use recursion and struct.