用C++动态改变指针的大小

Chr*_*_vr 0 c++ struct new-operator dynamic-allocation

我有以下结构

typedef struct DeviceInfo
{
    char[30] name;
    char[30] serial Number;

}DeviceInfo;

I am doing this    

DeviceInfo* m_DeviceInfo = new DeviceInfo[4];

// Populate m_DeviceInfo 
Run Code Online (Sandbox Code Playgroud)

然后我想重新调整大小m_DeviceInfo 为6,并希望保留Previous 4 Value.

怎么用c ++做?

ghi*_*hik 6

你不能用常规数组做到这一点.我建议你使用能够随着你添加更多元素而增长的向量(所以你甚至不必指定初始大小).