I'm having a problem storing certain processed values in my program into a structure array. These values contain 3 long integers, and I'm trying to store these values as arrays in my structure.
This is a simplified, relevant version of my whole code. Please help me make it work.
#include<iostream>
#define MAX 20
using namespace std;
struct DATA
{
int id, number;
float height;
} stuarray [MAX];
int main ()
{
long int1 =0; //contains integer values obtained from a file
long int2 =0; //contains integer values obtained from a file
long int3 =0 ; //contains integer values obtained from a file
cout<< stuarray[MAX].id << endl;
cout<< stuarray[MAX].number << endl;
cout<< stuarray[MAX].height << endl;
return 0;
}
okay, i'll explain my program. im reading values from a file as a string. after this im supposed to split them into 3 parts and store them in an array. this arrays should refer to the member variables in the structure. i have managed to read the values, split them, and convert all 3 of them into long ints. now i have to store these three values in the structure array. thank you all for ur help.
To store values in a specific element of stuarray:
stuarray[i].id = something;
stuarray[i].number = somethingElse;
stuarray[i].height = aFloatThisTime;
And note that for an array of MAX
entries, legal indexes are in the
range [0,MAX).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With