strtype.cpp

来自「此文件可以能帮你求体积」· C++ 代码 · 共 41 行

CPP
41
字号
// StrType.cpp: implementation of the StrType class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "StrType.h"
#include <iostream.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

StrType::StrType( char* ptr )
{
	len = strlen( ptr );
	p = (char *) malloc( len + 1 );
	if ( !p )
	{
		cout << "Allocation error\n";
		exit(1);
	}

	strcpy( p, ptr );
}

StrType::~StrType()
{
	cout << "Freeing p\n";
	free(p);
}

void StrType::Show()
{
	cout << p << "length:" << len;
	cout << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?