stl - Do I need to check capacity before adding an element to a vector in c++? -


i newbie c++ stl vectors sorry silly questions in advence. :) in program, have vector needs store unknown number of elements. have check if vector has achieved max_size before adding new element ? c++ compiler throw exception automatically when program tries add elements full vector ?

thank much, cassie

if std::vector has reached max size, attempting insert element result in underlying allocator throwing std::bad_alloc exception.

note, however, maximum size vector typically very, large (e.g., maximum value can represented size_t divided size of element type), unlikely, if not impossible, reach maximum size before run out of contiguous memory in vector can stored.


Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -