#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

class strtype {
	char *p;
	int len;
public:
	strtype();
	strtype(char *ptr,int bytes);
	~strtype();
	void show();
	char *getstring(){return p;}
	char getlength(){return len;}
};

strtype::strtype(char *ptr,int bytes)
{
	len = bytes;
	p = new char[len];
	if (!p){
		cout << "メモリ割り当てエラー\n";
		exit(1);
	}
	strncpy(p, ptr, len);
}
strtype::strtype()
{
	len = 255;
	p = new char[len];
	for(int i = 0;i < len; i++)
	{
		p[i] = '\0';
	}
}

strtype::~strtype()
{
	cout << "pを解放する。\n";
	delete p;
}


void strtype::show()
{
	cout << p << "-長さ:" << len << "\n";
}

int main()
{
	strtype s1("This is a test.",10), s2("I like C++.",5),s3;
	s1.show();
	s2.show();
	s3.show();
	cout << s1.getstring() << "\n";
	cout << s2.getstring() << "\n";
	cout << s3.getstring() << "\n";
	
	return 0;
}