This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
two structure-list questions, need help
- From: Zhidian Du <zdu at cs dot nmsu dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 10 Mar 2002 14:27:32 -0700
- Subject: 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;
}