我试图读入文件Rooms.txt:
Room ID: 1.
Room Name: Beach East.
Room Exits: 2, 3.
Room ID: 2.
Room Name: Beach West.
Room Exits: 1.
Room ID: 3.
Room Name: Forest.
Room Exits: 1,4.
Room ID: 4.
Room Name: Cave.
Room Exits: 3.
但我没有得到正确的输入。房间名称是-8987678678。我不知道为什么我会得到垃圾......这是我为读取文本文件而编写的函数,任何人都可以看到问题:
void Rooms :: loadRooms()
{
string fileName = "Rooms\\Rooms.txt";
ifstream infile(fileName);
string garbage;
int loadID;
string loadName;
string loadExits;
//while( )
//{
infile >>garbage;
infile >>loadID ;
infile >>garbage;
infile >>garbage;
infile >> loadName;
infile >> garbage;
infile >>garbage;
infile >>loadExits;
infile >>garbage;
cout << "Room ID: \t\t"<< loadID << "\n";
cout << "Room Name: \t\t"<< loadName << "\n";
cout << "Room Exits: \t\t" << loadExits<<"\n";
//}
}