私はテキストファイルから部屋を取り込んで変数の情報を使用しようとしているので、情報を取得した後、それをlinkedListに追加し、部屋IDで必要な部屋を検索してから、setRoomName =を部屋に使用します名前が見つかります。しかし、これは機能していません...誰でも問題を見ることができますか?
これが私のコードです:
#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 the 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 the Iterator.
for (itr.Start(); itr.Valid(); itr.Forth())
{
//If the object entered has the same first name as the one in the loop.
if (itr.Item().getRoomID() == searchByID)
{
//Print out the details from the 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();
}
どんな助けでも大歓迎です。