On Mon, 19 Jul 2004 13:02:34 +0100, "John Harrison"
<john_andronicus@hotmail.com> wrote:
[color=blue]
>
>"jhonyxxx" <jhonye@arrakis.es> wrote in message
>news:1vcnf05becceukndhnhf57jppcri9tc34m@4ax.com.. .[color=green]
>> I have the next programa in C++:
>>
>> #include <iostream.h> // C++ I/O routines
>> #include <list.h> // The STL list class
>> #include<stdio.h>
>> #include <string.h>
>> typedef struct
>> {
>> char nombre[30];
>> int edad;
>> } persona;
>> using namespace std;
>> int main () {
>> randomize();
>> // Create a new, empty linked list of int.
>> list<int> x;
>> int t;
>>
>> //for (t=1;t<=10;t++)
>> // x.push_front(t);
>> for (t=1;t<=100;t++)
>> {
>> if (t%2==0)
>> x.push_back(random(5000)+1);
>> else
>> x.push_front(random(5000)+1);
>>
>> //x.sort();
>> }
>> // Show all of the items now in the list.
>> list<int>::iterator i;
>>
>> for (i = x.begin(); i != x.end(); i++) {
>> cout << *i<<"--";
>>
>> }
>> printf("\n\n\n");
>>
>> printf("%d\n",x.size());
>> printf("%d\n",x.max_size());
>>
>> x.sort();
>> printf("\n\n\n");
>> for (i = x.begin(); i != x.end(); i++) {
>> cout <<*i<<"--";
>> }
>>
>> }
>>
>>
>>
>> If I use with a single list of int istīs ok but if the list containing
>> list<person> and I try generate the items with
>> persona ficha;
>> strcpy(ficha.nombre,"hola");
>> ficha.edad=40;
>> and then I try to see with
>>
>>
>>
>> for (i = x.begin(); i != x.end(); i++) {
>> cout << i->nombre<<"--";
>> cout <<i->edad<<"--";
>> }
>>
>> the programa break down and tell to me that exists errors for
>> compiling in the cout sentences, the exact message is :
>>
>> pointer to structure requeired on left side -> or ->*
>>
>> I have change al type of opertors over the iterators and I donīt
>> solve the problem, what is wrong?
>> Seems that I use list with atomic elements int, float char etc. all is
>> ok but if the list is wit struct the iterator seems turn fool.
>> help, me please thank you!!
>>
>>
>>
misruga@public.ibercaja.es
>>[/color]
>
>Are you sure that you changed this
>
> list<int>::iterator i;
>
>to this?
>
> list<person>::iterator i;
>
>
>If you did then maybe you are using a very old version of the STL. What you
>have written should work.
>
>If it doesn't work then try this
>
> for (i = x.begin(); i != x.end(); ++i) {
> cout << (*i).nombre<<"--";
> cout << (*i).edad<<"--";
> }
>
>But a better solution would be to get a more modern version of the STL. For
>instance have a look at
www.stlport.org for a free version of the STL that
>works with many different compilers. Which compiler are you using at the
>moment?
>
>john
>[/color]
My compiler is Borland c++ v5