Update 动态数组.cpp
This commit is contained in:
parent
93f3d96f03
commit
1ca9bceb61
@ -1,5 +1,14 @@
|
||||
#include<iostream>
|
||||
char *sPtr; //存放字符串的指针
|
||||
s="哈哈"
|
||||
sPtr = new char[strlen(s)+1];
|
||||
strncpy(sPtr,s;
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user