mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-03 18:43:52 +08:00
Update 动态数组.cpp
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user