如何添加和删除元素"重新缩放"数据?如何计算矢量的大小(我相信它是跟踪的)?任何其他额外的资源来了解矢量将不胜感激.
我想使用std :: vector来动态分配内存.场景是:
int neededLength = computeLength(); // some logic here
// this will allocate the buffer
std::vector<TCHAR> buffer( neededLength );
// call a function that accepts TCHAR* and the number of elements
callFunction( &(buffer[0]), buffer.size() );
Run Code Online (Sandbox Code Playgroud)
上面的代码有效,但这&(buffer[0])看起来很难看.是否有更优雅的方式来实现相同的目标?