1 int main() 2 { 3 char *s2 = "jwdajkj"; 4 char *s1 = new char[strlen(s2)+1]; 5 6 char *s3 = static_cast<char*> (memcpy(s1, s2, strlen(s2) + 1)); 7 printf("%p,%p\n", s3, s1); 8 cout << s3 << endl; 9 cout << &s3[0] << endl; 10 cout << static_cast<void*>(s3) << endl; 11 }
需要轉換為void*指針,重載的操作符<<遇到地址會自動輸出字符串