【发布时间】:2014-05-11 15:27:54
【问题描述】:
我有一个错误“_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)”,不知道该怎么办..
person.h
#ifndef _person_H
#define _person_H
class person
{
private:
char * name;
int * age;
char * address;
public:
void get_info(void);
void show_info(void);
person();
~person();
};
#endif _person_H
person.cpp
#include "stdafx.h"
#include <stdlib.h>
#include <string>
#include "person.h"
#include <iostream>
using namespace std;
person::person()
{
this->name = new char[50];
this->age = new int;
this->address = new char[50];
}
person::~person()
{
delete this->name;
delete this->age;
delete this->address;
}
void person::get_info()
{
cout << "write name and surname:" << endl;
cin >> name;
cout << endl;
cout << "write age:" << endl;
cin >> *(age);
cout << endl;
cout << "write address:" << endl;
cin >> address;
cout << endl;
}
void person::show_info()
{
cout << "Name and surname:" << name << endl;
cout << "Age:" << *age << endl;
cout << "Address:" << address << endl;
}
main.cpp
#include "stdafx.h"
#include "person.h"
int _tmain(int argc, _TCHAR* argv[])
{
int i;
person * newperson = new person[5];
for (i = 0; i<5; i++){
newperson[i].get_info();
}
for (i = 0; i<5; i++){
newperson[i].show_info();
}
delete newperson;
return 0;
}
你能帮我解决这个错误吗?而且我还想知道,如何将 2 个单词(姓名和姓氏)写入变量 "name" ?用“cin >> name”我只能写1个字...
【问题讨论】:
-
您使用的是reserved identifier。我还建议阅读 How to Debug Small Programs 以更好地了解如何调试它。
标签: c++