Initialization of Vector in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kuldeep senger
    New Member
    • Apr 2011
    • 1

    Initialization of Vector in C++

    Hello Everyone

    I want to know how can we initialize a vector of unknown length with some definite value ( example:- 0 ) like we did in array with memset().

    Any suggestions are really appreciated!
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Use vector::resize or vector::insert

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      vectors don't have unknown length. Use the size() method to get the number of elements and just iniialize them in a loop. Unless they are C++ objects with constructors.

      Comment

      Working...