The code ist'n compile. Where is problem?
I'm using Dev C++.
using namespace std;
struct kraj
{
sring nazwa;
int ludzie;
kraj* next;
kraj()
{
next = NULL;
}
kraj(string nazwa, int ludzie)
{
this-> nazwa = nazwa;
this-> ludzie = ludzie;
next = NULL;
}
void prints(kraj *lol)
{
cout<<lol->nazwa<<" "<<lol->ludzie<<endl;
}
};
void add(kraj* &head, string nazwa, int ludzie)
{
kraj* nowy = new kraj(nazwa, ludzie);
if(head==NULL)
{
head = nowy;
return;
}
if(head->ludzie > nowy->ludzie)
{
nowy->next = head;
head = nowy;
return;
}
kraj* temp = head;
while(temp->next)
{
if(temp->next->ludzie > nowy->ludzie)
{
nowy->next=temp->next;
temp->next = nowy;
return;
}
temp=temp->next;
}
temp->next = nowy;
}
void print(kraj* head)
{
while(head)
{
head->prints(head);
head=head->next;
}
}
void printif(kraj* head,int x)
{
while(head)
{
if(head->ludzie>x)
{
head->prints(head);
}
head=head->next;
}
}
void save(kraj* head)
{
ofstream file;
file.open("konduktor.txt",ios::out);
while(head)
{
file<<head->nazwa<<" "<<head->ludzie<<endl;
head=head->next;
}
file.close();
}
kraj* open()
{
kraj* head = NULL;
string nazwa;
int ludzie;
ifstream file;
file.open("konduktor.txt",ios::in);
while(!file.eof())
{
file>>nazwa;
file>>ludzie;
if(file.eof())
{
return head;
}
add(head,nazwa,ludzie);
}
file.close();
return head;
}
void saveb(kraj* head)
{
ofstream file;
file.open("balon.txt",ios::out | ios::binary);
while(head)
{
file.write((char*)&head->nazwa,sizeof(head->nazwa));
file.write((char*)&head->ludzie,sizeof(head->ludzie));
if(head->next==NULL)
{
break;
}
head=head->next;
}
file.close();
}
kraj* openb()
{
kraj* head = NULL;
string nazwa;
int ludzie;
ifstream file;
file.open("balon.txt",ios::in | ios::binary);
while(!file.eof())
{
file.read((char*)&nazwa,sizeof(nazwa));
file.read((char*)&ludzie,sizeof(ludzie));
if(file.eof())
{
return head;
}
add(head,nazwa,ludzie);
}
file.close();
return head;
}
int main()
{
kraj* head = NULL;
add(head,"Polska",10);
add(head,"Polska",2);
add(head,"Polska",21);
add(head,"Polska",4);
add(head,"Polska",5);
save(head);
print(head);
saveb(head);
kraj* drugi = openb();
cin.sync();
cin.get();
}
You need to post the error, and show use the line of code the compiler stops on.