我的显示功能有问题
An issue with my display function
我正在为类做一个项目,该项目雇用了一个叫做 employee 的类。我遇到问题的地方是显示功能。所有内容都正确显示,直到最后它继续输出最终抛出的符号列表:
引发异常:读取访问冲突。 这很0xFF4000。
我已经缩小到显示功能或输出显示的循环。对此问题的任何帮助将不胜感激。
#include <iostream>
#include <iomanip>
using namespace std;
class Employee {
private:
int empcode;
char empname[10];
public:
void getdata();
void display();
};
void Employee::getdata() {
cout << "nNAME : ";
cin >> empname;
cout << "nCODE : ";
cin >> empcode;
}
void Employee::display() {
cout << endl << setw(20) << empname << setw(10) << empcode << endl;
}
int main()
{
Employee Emp[6];
cout << "Enter employee details:n ";
for (int i = 0; i<6; i++)
{
cout << "nemployee " << i + 1 << endl;
Emp[i].getdata();
}
cout << "nEmployee details are as follows :";
cout << "nn" << setw(20) << "NAME" << setw(10) << "CODE";
cout << "n------------------------------";
for (int i = 0; 1 <= 6; i++)
Emp[i].display();
return 0;
}
你的第二个循环是错误的:
对于 (整数 i = 0;1 <= 6
;i++(
应该是:
for (int i = 0; i < 6; i++)
1 < 6
会一直循环,但是你的i++
每次迭代都会增加,当它得到6时,它会尝试访问不存在的元素Emp[6]
,只有Emp[0]...Emp[5]
相关文章:
- 我似乎对if/else的基本语句有问题:/
- 是否有任何C++功能可以对地图进行排序?
- 我在范围内未声明的错误类有问题
- 我的C++语言蛮力算法有问题
- 我关于函数"Assert"的C++代码有问题
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C++类中的友元函数有问题?
- 我对数组即 0x6dfe78 有问题
- 我对 std::unique(算法)C++有问题
- 使用 fstream 库并在屏幕上打印的文件有问题?
- 这个模板为什么有问题?如何正确编译
- 我对 MyGraph 属性顶点名称和边权重有问题
- delete[]有问题,如何部分删除内存
- 我有模板功能.通过使用函数std::for_each,用这个容器中的最大数字替换每个正数
- 在C++中使用exit()退出程序有问题吗
- 我的显示功能有问题
- 二叉搜索树在插入功能方面有问题
- 有问题使循环工作与功能相结合
- 结构功能有问题
- 无效功能有问题