This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

two structure-list questions, need help


Hello, I have two questions:

my program is a structure list.

My qustion 1:
why cannot I put 

	struct person_type{
	  int ssn;
	  string address;
	};
	typedef struct person_type person;

inside the main function?


My question 2:
what's wrong with the sentence
    cout << *iter.ssn<< endl;
how to change it?


Thank you in advance.
Z. Du


//my program is as follows:
#include <iostream>
#include <list>
#include <string>
using namespace std;

struct person_type{
  int ssn;
  string address;
};
typedef struct person_type person;


int main(void)
{
  list<person> blah;
  person p1, p2;

  p1.ssn = 10;
  p1.address = "first";

  p1.ssn = 20;
  p1.address = "second";


  blah.push_back(p1);
  blah.push_back(p2);


  for (list<person>::iterator iter=blah.begin(); iter!=blah.end();
iter++){
    cout << *iter.ssn<< endl;
  }
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]