CPlusPlusThings/practical_exercises/key_exercises/动态数组.cpp
2020-06-14 19:25:27 +08:00

15 lines
230 B
C++

#include<iostream>
#include<cstring>
int main() {
char *sPtr;
const char* s="hello";
sPtr = new char[strlen(s)+1];
strncpy(sPtr,s,strlen(s));
std::cout << sPtr << std::endl;
delete sPtr;
return 0;
}