01/10/2018, 10:51

Visual Studio in ra thêm ký tự

định nghĩa Contructor của em

cGrandInt::cGrandInt(char* str)
{
    int j =0;

	if(str[0] == '-')
	{
		mSign = false;
		mGrand = new char[(strlen(str))-1];
		for(int i = 1; i < strlen(str); i++)
		{
		//	int j = 0;
			mGrand[j] = str[i];
			j++;
		}
	}
	else
	{
		mSign = true;
		mGrand = new char[strlen(str)];
		for(int i = 0; i < strlen(str); i++)
		{
			mGrand[j] = str[i];
			j++;
		}
	}
}

và hàm show

void cGrandInt::show_GrandInt()
{
	if(mSign == true)
	{
		cout << mGrand;
	}
	else if(mSign == false)
	{
		cout << "-" << mGrand;
	}
	cout << "

";
}
Phạm Minh Anh Hữu viết 12:55 ngày 01/10/2018
cGrandInt::cGrandInt(char* str)
{
    int j =0;

	if(str[0] == '-')
	{
		mSign = false;
		mGrand = new char[(strlen(str))];
		for(int i = 1; i < strlen(str); i++)
		{
			mGrand[j] = str[i];
			j++;
		}
        mGrand[strlen(str)] = '\0';
	}
	else
	{
		mSign = true;
		mGrand = new char[strlen(str)+1];
		for(int i = 0; i < strlen(str); i++)
		{
			mGrand[j] = str[i];
			j++;
		}
        mGrand[strlen(str)] = '\0';
	}
}

Bạn thử đoạn code trên xem được chưa, hình như do bạn thiếu kí tự kết thúc chuỗi.

Nguyễn Hữu Đức viết 13:01 ngày 01/10/2018

mình thêm vào chạy được rồi. cảm ơn bạn

Bài liên quan
0