#include <iostream> using namespace std; void StrCpy(char **pDestination, char *pSource); void main() { char *pString = NULL; StrCpy(&pString, "ganquanfu"); cout << pString << endl; delete pString; pString = NULL; char *pTest = NULL; StrCpy(&pTest, "ASFASDFWFWQFRRQWERFEQWFSAFSdfasdfsafsafsdafssdfsadfsfsdfsdfdssfsadfsadfsdfsf"); cout << pTest << endl; delete pTest; pTest = NULL; int tem; cin >> tem; } void StrCpy(char **pDestination, char *pSource) { char *pResult; int i= 0; int len = 0; while(pSource[i]!='\0') { i++; len++; } *pDestination = new char[len + 1]; pResult = *pDestination; int j = 0; while(j < len) { **pDestination = pSource[j]; ++(*pDestination); ++j; } **pDestination = '\0'; *pDestination = *pDestination - len; }
转载于:https://www.cnblogs.com/ganquanfu2008/p/3153099.html