|
本帖最后由 zzxpieces 于 2019-7-28 11:38 编辑
代码:
1.Student类
- #pragma once
- #include<iostream>
- #include <string>
- #include<iomanip>
- using namespace std;
- class CStudent
- {
- public:
- char* p_name;
- char sex;
- int num;
- int age;
- CStudent();
- CStudent(char* t_name, char t_sex, int t_num, int t_age);
- ~CStudent();
- };
复制代码- #include "stdafx.h"
- #include "Student.h"
- CStudent::CStudent()
- {
- }
- CStudent::CStudent(char* t_name, char t_sex, int t_num, int t_age)
- {
-
- int len = strlen(t_name);
- p_name = new char[len + 1];
- memset(p_name, 0, len + 1);
- strcpy(p_name, t_name);
- }
复制代码
2.主程序
- #include "stdafx.h"
- #include<iostream>
- #include <string>
- #include<iomanip>
- #include "Student.h"
- using namespace std;
- void test()
- {
- CStudent Stu1;
- }
- int main()
- {
- test();
- CStudent* pStud = new CStudent("lisssssssssssssssssssssssssssssssssssssssssssssssssssswwss", 'm', 1001, 24);
- cout << " cout " << endl;
- return 0;
- }
复制代码
按照教程编写玩程序后进行单步调试,当执行到Student类的构造函数的第一条语句
- int len = strlen(t_name);
复制代码
会报错如下图所示,但是在视频里是可以通过的,然后查询了百度好像也没有确切的说明,但是如果直接逐过程调试,是不会报错。 |
上一篇: 我设置了开机启动,但文件完全找不到,求解,谢谢下一篇: 八皇后问题
|