new演算子


サンプル


		
#include	<iostream>

#include	<cstring>

#include	<new>
//#include	<malloc.h>

using namespace std;

char *szCstrStrcat(char *string1, char *string2,   //In
                   char *buffer)                   //Out
{
	//2つの文字列を結合してbufferに複写する。戻り値はbufferを返す。

	char	*buffer_temp;

	try
	{
		buffer_temp = new char [(strlen(string1)) + (strlen(string2)) + 1];
	}

	//new演算子の例外処理
	catch(bad_alloc xa){
		throw szExtErrMsg("ERROR", __FILE__, __LINE__);
	}

	sprintf(buffer_temp, "%s%s", string1, string2);

	sprintf(buffer, "%s", buffer_temp);

	//メモリの開放
	delete [] buffer_temp;

	return buffer;

}
		

<戻る>