你如何初始化C ++中的动态数组? [英] How do you initialise a dynamic array in C++?
本文介绍了你如何初始化C ++中的动态数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何做到这一点静态数组初始化的动态等效的:
字符C [2] = {}; //设置所有成员'\\ 0';
在换言之,创建一个动态阵列初始化为终止字符的所有值:
的char * C =新的char [长度] //我如何修改呢?
解决方案
的char * C =新的char [长度]();
How do I achieve the dynamic equivalent of this static array initialisation:
char c[2] = {}; // Sets all members to '\0';
In other words, create a dynamic array with all values initialised to the termination character:
char* c = new char[length]; // how do i amend this?
解决方案
char* c = new char[length]();
这篇关于你如何初始化C ++中的动态数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文