Opis problemu w komentarzu.
#include <iostream>
#include <new>
#include <string>
using namespace std;
struct element
{
string dane;
int wiek;
element *nastepny;
};
int main(void)
{
element *glowa = NULL;
element *nowy;
char znak;
for(;;)
{
cout<<"Nowy element? (t/n): ";
cin>>znak;
if(znak == 't')
{
try{nowy = new element;}
catch(bad_alloc){cout<<"No more space!";break;}
cout<<"Podaj dane osobowe: ";
// cin.ignore();
getline(cin, nowy->dane); // dlaczego ta linia kodu jest pomijana jak cin.ignore() jest wykomentowany
// dziala jak jest malo kodu
cout<<"Podaj wiek: ";
cin>>nowy->wiek;
nowy->nastepny = glowa;
glowa = nowy;
}
else
{
element *temp = glowa;
while(temp != NULL)
{
cout<<"Dane: "<<temp->dane<<endl;
cout<<"Wiek: "<<temp->wiek<<"\n\n";
temp = temp->nastepny;
}
break;
}
}
cin.ignore();
return 0;
}