4.30 复制字符串c风格

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	char src[] = "hello";
	char dest[] = "world!";

	int sizeSrc = sizeof(src)/sizeof(src[0]);
	int sizeDest = sizeof(dest)/sizeof(dest[0]);

	char *result = new char[sizeSrc+sizeDest];
	strcpy(result,src);
	strcat(result," ");
	strcat(result,dest);
	
	cout<<result;

	delete [] result;
}

  

posted on 2011-12-01 11:05  york_software123  阅读(113)  评论(0编辑  收藏  举报

导航