尝试创建结构对象,在位置0x3FE00000中创建访问冲突写入错误 我正在学习使用结构和制作基于文本的RPG,并且我知道项目应该是我的代码中的一个类,但是,因为我使用结构,我对C++和编程是新的,我不理解我的代码到底出了什么问题,也不知道如何修复它,在尝试创建一个名为Pror的结构对象时,会发生错误。(我还想为我混乱的代码道歉,我正在胡闹,一旦我得到了我能用的东西,我就会清理它。)

尝试创建结构对象,在位置0x3FE00000中创建访问冲突写入错误 我正在学习使用结构和制作基于文本的RPG,并且我知道项目应该是我的代码中的一个类,但是,因为我使用结构,我对C++和编程是新的,我不理解我的代码到底出了什么问题,也不知道如何修复它,在尝试创建一个名为Pror的结构对象时,会发生错误。(我还想为我混乱的代码道歉,我正在胡闹,一旦我得到了我能用的东西,我就会清理它。),c++,structure,C++,Structure,这是我第一次尝试,我没有尝试太多,因为我不确定到底要尝试什么 #include "pch.h" #include <iostream> #include <string> #include <fstream> using namespace std; struct item { double resistance, attack; string name; }; item none, WoodenBoots, LeatherChestpla

这是我第一次尝试,我没有尝试太多,因为我不确定到底要尝试什么

#include "pch.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct item {
    double resistance, attack;
    string name;
};
item none, WoodenBoots, LeatherChestplate, WoodenShield, WoodenClub, WoodenSword;


struct mobs {
    int health, attack;
    double droprate, resistance;
    item drops[3];
};

item GetData(string object);


int main()
{
    none.attack = 0;
    none.resistance = 0;
    none.name = "none";
    WoodenBoots.resistance = .05;
    WoodenBoots.attack = 0;
    WoodenBoots.name = "Wooden Boots";
    LeatherChestplate.resistance = .2;
    LeatherChestplate.attack = 0;
    LeatherChestplate.name = "Leather Chestplate";
    WoodenShield.resistance = .1;
    WoodenShield.attack = 0;
    WoodenShield.name = "Wooden shield";
    WoodenClub.resistance = 0;
    WoodenClub.attack = 1.2;
    WoodenClub.name = "Wooden Club";
    WoodenSword.resistance = .05;
    WoodenSword.attack = 1.5;
    WoodenSword.name = "Wooden Sword";

    mobs goblin;
    goblin.attack = 1;
    goblin.health = 10;
    goblin.droprate = .5;
    goblin.resistance = .1;
    goblin.drops[1] = WoodenClub;
    goblin.drops[2] = WoodenShield;
    goblin.drops[3] = WoodenBoots;

    mobs Alpha_Goblin;
    Alpha_Goblin.attack = 2;
    Alpha_Goblin.health = 15;
    Alpha_Goblin.droprate = .5;
    Alpha_Goblin.resistance = .1;
    Alpha_Goblin.drops[1] = WoodenSword;
    Alpha_Goblin.drops[2] = WoodenShield;
    Alpha_Goblin.drops[3] = LeatherChestplate;

    struct pdata {
        item Playeritem[6];
        item PlayerWeapon;
    }player;

    player.PlayerWeapon = WoodenSword;
    cout << player.PlayerWeapon.name << endl;

    player.PlayerWeapon = GetData("weapon");
    player.Playeritem[0] = GetData("sheild");
    player.Playeritem[1] = GetData("head");
    player.Playeritem[2] = GetData("torso");
    player.Playeritem[3] = GetData("legs");
    player.Playeritem[4] = GetData("feet");
    player.Playeritem[5] = GetData("hands");
    string weapon = player.PlayerWeapon.name;
    cout << weapon << endl;
    system("pause");
}
#包括“pch.h”
#包括
#包括
#包括
使用名称空间std;
结构项{
双重抵抗、双重攻击;
字符串名;
};
项目无,木质木本,皮革箱板,木质护盾,木质护盾,木质护盾;
结构暴徒{
int健康,攻击;
双下降率,阻力;
项目下降[3];
};
item GetData(字符串对象);
int main()
{
无。攻击=0;
无。电阻=0;
none.name=“none”;
木本植物抗性=.05;
WoodenBoots.attack=0;
WoodenBoots.name=“木制靴子”;
革胸板。阻力=.2;
LeatherChestplate.attack=0;
LeatherChestplate.name=“LeatherChestplate”;
WoodenShield.阻力=.1;
WoodenShield.attack=0;
WoodenShield.name=“木质盾牌”;
木质润滑脂。阻力=0;
WoodenClub.attack=1.2;
WoodenClub.name=“木制俱乐部”;
WoodenSword.resistance=.05;
WoodenSword.attack=1.5;
WoodenSword.name=“木剑”;
暴徒妖精;
地精攻击=1;
地精:健康=10;
地精。下降率=.5;
地精阻力=0.1;
地精滴[1]=森林俱乐部;
地精.水滴[2]=木盾;
地精.水滴[3]=木本植物;
乌合之众阿尔法妖精;
Alpha_Goblin.attack=2;
Alpha_Goblin.health=15;
Alpha_Goblin.droprate=.5;
Alpha_Goblin.阻力=0.1;
Alpha_Goblin.drops[1]=WoodenSword;
阿尔法·地精·水滴[2]=木盾;
阿尔法·地精·水滴[3]=皮革胸板;
结构数据{
项目Playeritem[6];
项目播放武器;
}玩家;
player.PlayerWeapon=WoodenSword;

C++数组中的CUT

由0到NUMLY元素- 1<P/> 所以如果你申报

int myArray[3];
然后尝试访问:

myArray[3] = 5;
您将获得未定义的行为,这些行为可能会表现为访问冲突,具体取决于编译器和调试设置


在VisualStudio中,可以使用异常设置并在调试时运行访问异常异常,并在其被抛出之前执行停止。

熟悉IDE的调试器并检查堆栈跟踪的好起点。C和C++中的数组具有从零开始的索引,而不是一个。“NeilButterworth”的定义是什么?t意味着
drops
表的有效元素是
drops[0]
drops[1]
drops[2]
。我想你对
player.PlayerItem
做得很好。谢谢,我错过了,我现在在另一个名为Xutility的脚本中遇到了另一个写入错误。请使用调试器,并告诉我们在抛出异常之前,哪一行是最后一行执行。你将遇到访问冲突。->你将得到未定义的行为至少可能在访问冲突中显示。