J
jhonyxxx
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!!
(e-mail address removed)
#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!!
(e-mail address removed)