I am trying to find out the adjacent list of my cities class.
I did this function but there are a bug somewhere in the code.
Can anybody suggest me what to do. I will use vector and list.
list<City*> City::getAdjacent(){
// return a copy of the adjaceny list
std::vector<std::list<City>> clist;
// open file
string fileContents;
int y,z;
string x;
ifstream fin;
fin.open("townlist.txt");
while(fin>>x>>y>>z)
{
// getline(fin,fileContents,'\x1A');
istringstream iss(fileContents);
// Read from the file contents
iss >> x;
iss >> y;
iss >> z;
clist.push_back(x);
// Display the integers
//cout << x << ' ' << y << ' ' << z << '\n';
}
fin.close();
std::vector<std::list<City>> iterator i;
int c = 0;
for(i = clist.begin(); i != clist.end(); ++i)
{
cout<<c<<endl;
std::list<City> li = *i;
for(std::list<City>::iterator iter = li.begin(); iter != li.end(); ++iter)
{
cout<<*iter<<endl;
}
c++;
}
}