two structure-list questions, need help

Zhidian Du zdu@cs.nmsu.edu
Sun Mar 10 13:27:00 GMT 2002


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;
}



More information about the Gcc mailing list