自己写了一个类,但是输出有问题
这是调试界面,下面是代码,求助啊,为什么输出有烫口
#include"stdafx.h"
#include <string.h>
#include <iostream>
using namespace std;
class Dogs
{
public:
char name[5];
int age;
void dogspeak()
{
cout << "wang wang !!" << endl;
}
void dogrun()
{
cout << "I am running !!" << endl;
}
};
int main(void)
{
Dogs white_dog;
Dogs *p = new Dogs();
if (NULL == p)
{
//falsed
return 0;
}
cout << "please input your dog's name:" << endl;
for (int i = 0; i < 5; i++)
{
cin >> white_dog.name[i];
}
cout << "The dog is ______ years old." << endl;
cin >> white_dog.age;
cout << "The white dog is " << white_dog.age << " years old." << endl;
cout << "name is " << white_dog.name << endl;
cout << "please input your another dog's name:" << endl;
for (int i = 0; i < 5; i++)
{
cin >> p->name[i];
}
cout << "The another dog is ______ years old." << endl;
cin >> p->age;
cout << "The " << p->name <<" dog is " << p->age << " years old." << endl;
cout << "name is " << p->name << endl;
delete p;
p = NULL;
system("pause");
return 0;
}