Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;向量错误:下标超出范围 我是C++ NoOB,目前正在尝试创建一个基于文本的迷宫游戏。我正在用一个向量(表示动态大小)替换当前正在工作的数组,并读取一个包含字符的txt文件_C++_Vector_Runtime Error_Subscript - Fatal编程技术网

C++;向量错误:下标超出范围 我是C++ NoOB,目前正在尝试创建一个基于文本的迷宫游戏。我正在用一个向量(表示动态大小)替换当前正在工作的数组,并读取一个包含字符的txt文件

C++;向量错误:下标超出范围 我是C++ NoOB,目前正在尝试创建一个基于文本的迷宫游戏。我正在用一个向量(表示动态大小)替换当前正在工作的数组,并读取一个包含字符的txt文件,c++,vector,runtime-error,subscript,C++,Vector,Runtime Error,Subscript,问题:我没有收到IDE错误,但收到运行时错误:调试断言失败!表达式:向量下标超出范围 我使用了pushback而不是RoomFile=data,但我不知道是否需要修改其他函数。我在另一个类(player)中读取数组/向量数据,并在需要时包含代码 我到处寻找解决方案,但找不到任何使用类似向量结构的项目。我做错了什么 房间.h #pragma一次 #包括 #包括“stdafx.h” 教室 { private://函数访问的数据 焦层; 炭壁; 炭门; 整数宽度; 内部高度; 公众: std::矢量数

问题:我没有收到IDE错误,但收到运行时错误:调试断言失败!表达式:向量下标超出范围

我使用了pushback而不是RoomFile=data,但我不知道是否需要修改其他函数。我在另一个类(player)中读取数组/向量数据,并在需要时包含代码

我到处寻找解决方案,但找不到任何使用类似向量结构的项目。我做错了什么

房间.h
#pragma一次
#包括
#包括“stdafx.h”
教室
{
private://函数访问的数据
焦层;
炭壁;
炭门;
整数宽度;
内部高度;
公众:
std::矢量数据;
北面*房间;
东*室;
房间*南;
西*室;
下一个房间*;
int NorthX;
印度北部;
int EastX;
国际东方;
int SouthX;
南部内陆;
int WestX;
国际西部;
字符文件;
//函数的去向
房间(空);
void CreateRoom(int RoomNo);
作废打印室();
~房间(空);
};
Room.cpp
#包括
#包括
#包括
#包括
#包括
#包括“房间h”
#包括
使用名称空间std;
房间::房间(空)
{
地板=“”;
墙=“#”;
门='X';
宽度=11;
高度=11;
北=0;
东=0;
南=0;
西=0;
Next=0;
NorthX=0;
NorthY=0;
EastX=0;
EastY=0;
SouthX=0;
SouthY=0;
WestX=0;
WestY=0;
}
无效房间::CreateRoom(内部房间号)
{
std::矢量数据;
字符文件[255];
河流充填;
细流ss;
//从文件加载当前文件室
ss在PrintRoom()函数中

cout << data[col * height + row];

cout我认为这就是错误所在:您在
PrintRoom
中打印的是类内的
std::vector data
,而您填写的
std::vector data
CreateRoom
方法的本地部分

void Room::CreateRoom(int RoomNo)
{
std::vector<char> data; // remove this to solve
void Room::CreateRoom(int RoomNo)
{
std::vector data;//删除此项以解决

< /代码> UM,因此断言会说它在哪里失败。这是有用的信息。为什么他们不能教C++正确地在UNIS上?程序:C:\Windows \Stults\MSVCP11.DLL文件:D:\Script文件(x86)\microsoft visual studio 11.0\vc\include\vector Line:1140此断言反馈有助于发现问题?您需要堆栈跟踪。为发现该问题已被修正而欢呼,但仍会出现运行时错误!一个体面的编译器将对此发出警告。
// throw -- terminate on thrown exception REPLACEABLE
#define _HAS_EXCEPTIONS 0
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <crtdbg.h>

_STD_BEGIN

#ifdef _DEBUG
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *message, const wchar_t *file, unsigned int line)
{   // report error and die
    if(::_CrtDbgReportW(_CRT_ASSERT, file, line, NULL, L"%s", message)==1)
    {
        ::_CrtDbgBreak();
    }
}
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const unsigned short *message, const unsigned short *file, unsigned int line)
{   // report error and die
    _Debug_message((wchar_t *) message, (wchar_t *) file, line);
}

#endif

_STD_END
cout << data[col * height + row];
cout << data[row * height + col];
void Room::CreateRoom(int RoomNo)
{
std::vector<char> data; // remove this to solve