I am beginning to get a little familiar with the stl
and my problem is as follows. In all the tutos they tell you the functions, like adding elements and showing them, traversing them, etc. I have this structure:
struct Libro{
string nombre;
int codigo;
bool disp;
};
and this list list <Libro> libro
With this function I add books to the list:
Libro insertarlibro(){
string nombre;
int codigo;
bool disp=true;
cout<<"\nIngrese el nombre del libro: ";
getline(cin,nombre);
cout<<"\nIngrese el codigo: ";
cin>>codigo;
return{nombre,codigo,disp};
}
from the main
libro.push_back(insertarlibro())
and it is assumed that books are shown with this function:
void mostrarlibros( list<Libro> & sList )
{
list<Libro>::iterator pos;
pos = sList.begin();
while( pos != sList.end())
{
cout<<*pos<<endl;
pos++;
}
}
But obviously, if the structure I have consists of three data name, code and availability, *pos
will not show the 3, then I want to know what to put in cout<<
to be able to show the name, code and disp of each book added. I have searched a lot and I do not get a guide on how to show the elements of an aggregate structure in a container in this case the list