When you do v1.insert(v1.begin(), 7)
, you are just inserting an element at the beginning of v1. You don’t expect that, after inserting an element, the number of elements stays the same.
I think what you want is simply v1[0] = 7
.
More Related Contents:
- Invalid operands to binary expression while implementing vector [closed]
- How to Systematically use each item in a Vector [closed]
- How to enforce move semantics when a vector grows?
- Does C++11 allow vector?
- Removing item from vector, while in C++11 range ‘for’ loop?
- Is this behavior of vector::resize(size_type n) under C++11 and Boost.Container correct?
- Is a moved-from vector always empty?
- C++ unordered_set of vectors
- std::vector, default construction, C++11 and breaking changes
- Is it possible to initialize std::vector over already allocated memory?
- How can I use something like std::vector?
- Initializer-list-constructing a vector of noncopyable (but movable) objects
- Compile time triggered range check for std::vector
- Why can’t I create a vector of lambdas (of the same type) in C++11?
- Why doesn’t emplace_back() use uniform initialization?
- How do I pass multiple ints into a vector at once?
- How can I resize a 2D vector of objects given the width and height?
- Can std::vector emplace_back copy construct from an element of the vector itself?
- Write concurrently vector
- What is a vector of vector of point? [closed]
- Using paragraphs 8.5.3p4 and p5 in the C++11 Standard, how do I prove that the snippet below doesn’t compile?
- C++11 allows in-class initialization of non-static and non-const members. What changed?
- c++ access static members using null pointer
- Is string::c_str() no longer null terminated in C++11?
- how to initialize a constexpr reference
- C++11 inheriting constructors and access modifiers
- Cleaning up an STL list/vector of pointers
- What happens when you call data() on a std::vector?
- How to know underlying type of class enum?
- Explicit Return Type of Lambda