Hey everyone. I am working on my final skills check for my intro C++ class and I am having some trouble. the problem is to take a descriptor and a value and tag it onto the end of a 2D array created in a struct, a la:

struct 2d
{
char descriptor;
int value;
}

The original array is read in from a text file. I am having trouble adding on the descriptor and value. so far i have....

bool trytoread(ifstream *ps,map2d *ppt)
{
   *ps>>(*ppt).descriptor;
   if (!*ps)
       return false;
   *ps>>(*ppt).value;
   if (!*ps)
       return false;
   return true;
}

in order to read in the file and get a count for the number of values in the file....

then in main:

while(trytoread(&inStream, &list[count]))
   {
       count++;
   }
   
   list[count+1].descriptor=descriptor;
   list[count+1].value=number;

   for(int j=0; j<count+1; j++)
       cout << list[j].descriptor << " " << list[j].value << endl;

this is the part I do not understand. descriptor and number have already been given as input with cin/cout statements. Instead of adding this to the list I just get a 0 where the descriptor etc. should be. any ideas? I can include my whole code if anyone wants to look at that, thanks.

put complete code.. at least I don't understand half your problem.
also I didn't know C++ allowed type names to start with numbers.

>>trytoread()
coding for that would be simplified if you pass the parameters using c++ references instead of pointers

bool trytoread(ifstream& ps,map2d& ppt)
{
   ps >> ppt.descriptor;
   if (!ps)
       return false;
   ps >> ppt.value;
   if (!ps)
       return false;
   return true;
}
while(trytoread(inStream, list[count]))
   {
       count++;
   }
This article has been dead for over six months. Start a new discussion instead.