c++ - setRoomName does not change the variable roomName -


im taking in rooms text file , trying use information in variables after take info in add linkedlist, search room want room id , use setroomname = room finds name. isnt working... can see problem ?

here code:

#include "rooms.h" #include "doublylinkedlist.h" #include <string> using namespace std;  doublylinkedlist<rooms> roomslist; doublylinkedlistiterator<rooms> itr = roomslist.getiterator();   rooms :: rooms() {     this->roomid = 0;     this->roomname = "";     this->roomexits = ""; }   rooms :: rooms(int roomid,string roomname,string roomexits)  {      this->roomid = roomid;      this->roomname = roomname;      this->roomexits = roomexits;  }     int rooms :: getroomid()     {         return roomid;     }     void rooms :: setroomid(int roomid)     {         this->roomid = roomid;     }     string rooms :: getroomname()     {     return roomname;     }     void rooms ::setroomname(string roomname)     {         this->roomname = roomname;     }     string rooms :: getroomexits()     {     return roomexits;     }     void rooms :: setroomexits(string roomexits)     {         this->roomexits = roomexits;     }  void rooms :: loadrooms()  {     string filename = "rooms\\rooms.txt";     ifstream infile(filename);     string garbage;     int loadroomid;     string loadroomname1;     string loadroomname2;     string loadroomexits;     while(infile >>garbage >> garbage >> loadroomid  >> garbage >>           garbage >> garbage >> loadroomname1 >> loadroomname2 >> garbage            >> garbage >> loadroomexits)     {          cout << "room id: \t\t"<< loadroomid << "\n";         cout << "room name: \t\t"<< loadroomname1 <<" " << loadroomname2 << "\n";         cout << "room exits: \t\t" << loadroomexits <<"\n";         string loadroomname = loadroomname1 + loadroomname2;         rooms r1 (loadroomid,loadroomname,loadroomexits);         roomslist.append(r1);     }   }  void rooms :: printrooms()     {         int index = 0;          //loop through iterator.         for(itr.start();itr.valid();itr.forth())         {             index++;             cout << "------------------rooms------------------\n";             cout << "--------------------------------\n";             cout << "position:\t\t" << index << "\n";             cout << "--------------------------------\n";             cout << "room id:\t\t" << itr.item().getroomid() << "\n";              cout << "room name:\t\t" << itr.item().getroomname() << "\n";              cout << "room exits:\t\t" << itr.item().getroomexits() << "\n";             cout << "------------------------------------------\n";         }         cout << "rooms: \t\t" << roomslist.getcount() << "\n";     }     string rooms :: searchbyroomid(int searchbyid) {     //loop through iterator.     (itr.start(); itr.valid(); itr.forth())         {             //if object entered has same first name 1 in loop.             if (itr.item().getroomid() == searchbyid)             {                 //print out details list.                 cout << "------------------------------------------\n";                  cout << "room id:\t\t" << itr.item().getroomid() << "\n";                  cout << "room name:\t\t" << itr.item().getroomname() << "\n";                  cout << "room exits:\t\t" << itr.item().getroomexits() << "\n";                 cout << "------------------------------------------\n";                 setroomid(itr.item().getroomid());                 setroomname(itr.item().getroomname());                 setroomexits(itr.item().getroomexits());                 cout << getroomid();                 cout << getroomname();                 cout << getroomexits();             }         }     return getroomname(); } 

any appreciated.

mistake found finding room id , setting id,name,exits same found. how can find change

setroomid(itr.item().getroomid()); setroomname(itr.item().getroomname()); setroomexits(itr.item().getroomexits()); 

instead of should give other value need set exmple

setroomid(789);  setroomname("room "); setroomexits("yes"); 

here found room's id,name,exits sets 789,"room ","yes" respectivly


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -