C++ 是我的文件输入导致我的";'的实例;标准::逻辑错误'&引用;?
我正在尝试进行一些文件输入,以便将房间的各个方面读入变量,然后将变量读入对象(房间是对象,而北、东、南和西的通道是对象) 我正在读取的文件如下所示:C++ 是我的文件输入导致我的";'的实例;标准::逻辑错误'&引用;?,c++,file-io,C++,File Io,我正在尝试进行一些文件输入,以便将房间的各个方面读入变量,然后将变量读入对象(房间是对象,而北、东、南和西的通道是对象) 我正在读取的文件如下所示: 2 3 The Start,-,+,red_key,-,axe blue_key The Landing,-,+,-,+, Master Bedroom,-,-,-,+,red_key The Kitchen,red_key,+,-,-, The Hall,-,+,-,+, The Exit!,-,+,-,+, 房间将放置在二维阵列中。我已经正确
2 3
The Start,-,+,red_key,-,axe blue_key
The Landing,-,+,-,+,
Master Bedroom,-,-,-,+,red_key
The Kitchen,red_key,+,-,-,
The Hall,-,+,-,+,
The Exit!,-,+,-,+,
房间将放置在二维阵列中。我已经正确地读取了文件中的行和列的数量,但是在房间的每一行的末尾,情况变得很糟糕。以下是我试图做的:
char discard = ',';
string roomName;
string nPassage;
string ePassage;
string sPassage;
string wPassage;
char lastChar;
string listOfItems;
for(int i = 0; i < this->rows; i++)
{
roomName.clear();
listOfItems.clear();
for(int j = 0; j < this->columns; j++)
{
getline(cinMaze, roomName, discard); cout << roomName << endl;
getline(cinMaze, nPassage, discard); cout << nPassage << endl;
getline(cinMaze, ePassage, discard); cout << ePassage << endl;
getline(cinMaze, sPassage, discard); cout << sPassage << endl;
getline(cinMaze, wPassage, discard); cout << wPassage << endl;
cinMaze >> lastChar; cout << "\"" << lastChar << "\"";
room roomInMaze(roomName, createPassageWay(nPassage), createPassageWay(ePassage), createPassageWay(sPassage), createPassageWay(wPassage));
theMaze[i][j] = roomInMaze;
if (lastChar != '\n')
{
cinMaze.putback(lastChar);
getline(cinMaze, listOfItems);
theMaze[i][j].addItem(listOfItems);
}
}
}
我对文件I\O或其他东西有什么不理解?您的编译器在哪一行说发生了
逻辑\u错误
?请阅读并尝试将此减少到复制错误的绝对最小示例(即从头开始)。这是你的额外工作。没错。但这不是免费的调试服务。它使我们更容易回答问题,并帮助您更好地理解问题。我们是志愿者。帮助我们帮助您。引用:没有标准库组件直接引发此异常。此异常应该作为派生类之一抛出,或者您自己抛出(或者您使用的库抛出)。您是否可以共享与std::logic_error
相关的部分?
The Start
-
+
red_key
-
"a"The Landing
-
+
-
+
"M"The Kitchen
red_key
+
-
-
"T"The Exit!
-
+
-
+
"T"The Exit!
-
+
-
+
"T"The Exit!
-
+
-
+