我想通过直接输入一个任意大小的字符串来创建一个字符数组,但又不想浪费多余的空间,要怎么做到呢?新手。。。
5条回答 默认 最新
- longzai1216 2015-04-14 18:31关注
char * newchar(const char * ps){
char * prt = 0;
if(ps){
int nlen = strlen(ps);
prt = new char[nlen+1];
strcpy(prt,ps);
}
return prt;
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报