Skip to content

Commit 1ca9bce

Browse files
authored
Update 动态数组.cpp
1 parent 93f3d96 commit 1ca9bce

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#include<iostream>
2-
char *sPtr; //´æ·Å×Ö·û´®µÄÖ¸Õë
3-
s="¹þ¹þ"
4-
sPtr = new char[strlen(s)+1];
5-
strncpy(sPtr,s;
2+
#include<cstring>
3+
4+
5+
int main() {
6+
7+
char *sPtr;
8+
const char* s="hello";
9+
sPtr = new char[strlen(s)+1];
10+
strncpy(sPtr,s,strlen(s));
11+
std::cout << sPtr << std::endl;
12+
delete sPtr;
13+
return 0;
14+
}

0 commit comments

Comments
 (0)