写入位置 0xDDDDDDDD 时发生访问冲突,怎么解决

qq_26206285 2018-06-10 05:39:17
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<Windows.h>//用于获取系统时间的两个头文件
#include<WinBase.h>
using namespace std;
class AirplaneInformation
{public:
string airplane_destination;//航班目的地
string flight_number;//定义航班号
string AC_ID;//飞机识别号
string data;//飞行日
int carrrying_capacity;//乘员定额
int residue_quantity;//余票量
AirplaneInformation()
{
airplane_destination = "0";
flight_number = "0";
AC_ID = "0";
data = "0";
carrrying_capacity = 0;
residue_quantity = 0;
};
AirplaneInformation(string a,string b,string c,string d,int e,int f)//构造函数赋初值
{
airplane_destination = a;
flight_number = b;
AC_ID = c;
data = d;
carrrying_capacity = e;
residue_quantity = f;
}
void show()//输出数据成员
{
cout << "航班目的地:"<<airplane_destination << " "<<"航班号:" << flight_number << " "<<"飞机号:"
<< AC_ID << " "<<"飞行日:" << data << " "
<<"成员定额:"<< carrrying_capacity << " " <<"余票量"<< residue_quantity << endl;
}
};
class Passenger//乘客
{public:
string name;
string password;//密码
Passenger()
{
name = "0";
password = "0";
};
Passenger(string a,string b)
{
name = a;
password = b;
}
};
class Manager//管理员
{public:
string name;
string password;
Manager()
{
name = "0";
password = "0";
};
Manager(string a,string b)
{
name = a;
password = b;
}
};
void writeData(Passenger a)//将a的数据写入到乘客文件中
{
fstream i; Passenger t;
i.open("passenger.dat", ios::out | ios::binary | ios::in);
do
{
i.read((char*)&t, sizeof(Passenger));
} while (!endMark2(t));
i.seekp(-long(sizeof(Passenger)), ios::cur);
i.write((char*)&a, sizeof(Passenger));
i.write((char*)&mark2, sizeof(Passenger));
i.close();
}
int login(string a,string b,int c)//登录账号
{
int p=0;
ifstream i,q;
Passenger h;
Manager e;
i.open("passenger.dat", ios::in | ios::binary);
q.open("manager.dat", ios::in | ios::binary);
if (c == 1)
{
i.seekg(0, ios::beg);
do
{
i.read((char*)&h, sizeof(Passenger));
} while (h.name != a && h.password != b && !endMark2(h));
if (h.name == a && h.password == b)
{
p = p + 1;
}
if (p)
{
cout << "验证成功,已登录" << endl;
}
else
{
cout << "您输入的账号和密码不匹配,请检查后重新输入" << endl;
}
return p;
}
if(c==3)
{
q.seekg(0, ios::beg);
do
{
q.read((char*)&e, sizeof(Manager));
} while (e.name != a && e.password != b && !endMark5(e));
if (e.name == a && e.password == b)
{
p = p + 1;
}
if (p)
{
cout << "验证成功,已登录" << endl;
}
else
{
cout << "您输入的账号和密码不匹配,请检查后重新输入" << endl;
}
return p;
}
i.close();
q.close();
}
void CreatePassenger()//创建一个乘客的新账号
{
string name, password="111111";
cout << "您正在创建一个新的航空客运订票系统的账户,请输入您的姓名" << endl;
cin >> name;
cout << "您的初始密码为111111,如需修改请输入1,否则输入0" << endl;
Passenger a;
int result;
cin >> result;
if (result)
{
{
cout << "请输入您要修改的密码:" << endl;
string m;
cin >> m;
Passenger a(name, m);
writeData(a);
}
cout << "密码修改成功" << endl;
}
else
{
Passenger a(name, password);
writeData(a);
}
}
int main()
cout << " =================================================" << endl;
cout << " 欢迎使用航空客运订票系统 " << endl;
cout << " =================================================" << endl;
cout << "当前时间为:" ;
time_data();
cout << endl;
cout << "请您先登录系统" << endl;
cout << " 1 用户登录 2 创建新用户 3 管理员登录" << endl;
int a, b;//用来选择操作功能
string m, n;//记录登陆者用户名和密码
string c;//记录要搜索的航班名称
cin >> a;
switch(a)
{case 1:L:
{
cout << "请输入您的账号和密码(用空格区分)" << endl;
cin >> m >> n;
if (login(m, n, 1))
break;
else
goto L;
}
case 2:
{
CreatePassenger();
cout << "新用户创建成功,请返回登录" << endl;
goto L;
break;
}
case 3:
{
cout << "请输入管理员的账号和密码(用空格区分)" << endl;
cin >> m >> n;
if (login(m, n, 3))
break;
else
goto L;
}
}system("pause");
}




在system("pause")之后就出现0x00C7C995 处有未经处理的异常(在 《面向对象程序设计》课程设计.exe 中): 0xC0000005: 写入位置 0xDDDDDDDD 时发生访问冲突。
请问各位怎么解决?
...全文
1879 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2018-06-11
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。 windows里常见的内存填充数据含义  * 0xABABABAB : Used by Microsoft's HeapAlloc() to mark "no man's land" guard bytes after allocated heap memory 漱 * 0xABADCAFE : A startup to this value to initialize all free memory to catch errant pointers 涵? * 0xBAADF00D : Used by Microsoft's LocalAlloc(LMEM_FIXED) to mark uninitialised allocated heap memory 很? * 0xBADCAB1E : Error Code returned to the Microsoft eVC debugger when connection is severed to the debugger 撅饰 * 0xBEEFCACE : Used by Microsoft .NET as a magic number in resource files 烫烫 * 0xCCCCCCCC : Used by Microsoft's C++ debugging runtime library to mark uninitialised stack memory 屯屯 * 0xCDCDCDCD : Used by Microsoft's C++ debugging runtime library to mark uninitialised heap memory 葺葺 * 0xDDDDDDDD : Used by Microsoft's free() or delete to mark freed heap memory 蕲蕲 * 0xDEADDEAD : A Microsoft Windows STOP Error code used when the user manually initiates the crash  * 0xFDFDFDFD : Used by Microsoft's C++ debugging heap to mark "no man's land" guard bytes before and after allocated heap memory  * 0xFEEEFEEE : Used by Microsoft's HeapFree() to mark freed heap memory
qq_26206285 2018-06-10
  • 打赏
  • 举报
回复

65,144

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧