c++ 一句代碼實現strcpy

#include <iostream>

int main(){
	const char *src = "hello world";  // 源字符串
	char *dest = new char[std::strlen(src)+1]{};

	// 實現strcpy
	for(int i=0; dest[i]=src[i]; i++);

	std::cout << dest << std::endl;

	delete[] dest;

	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章