Because a
is empty, a[i]
accesses it out of bounds for every possible i
, causing undefined behavior.
Use a.push_back(s[i])
to add characters to a
.
More Related Contents:
- How does vector’s growth function work? [closed]
- count how many months until Oct without using any thing but cout
- How to implement classic sorting algorithms in modern C++?
- Implementation C++14 make_integer_sequence
- How to create an std::function from a move-capturing lambda expression?
- What are some uses of decltype(auto)?
- Is it a conforming compiler extension to treat non-constexpr standard library functions as constexpr?
- Is it safe to link C++17, C++14, and C++11 objects
- Strongly typed using and typedef
- C++11: Correct std::array initialization?
- Is auto as a parameter in a regular function a GCC 4.9 extension?
- C++14 Variable Templates: what is their purpose? Any usage example?
- Pass by value vs pass by rvalue reference
- Why are lambda expressions not allowed in an unevaluated operands but allowed in the unevaluated portions of constant expressions?
- Default, value and zero initialization mess
- Is #pragma once part of the C++11 standard?
- Parallel Loops in C++
- How to extract the source filename without path and suffix at compile time?
- Is there a name for this tuple-creation idiom?
- Compile-time or runtime detection within a constexpr function
- Arity of a generic lambda
- Calling initializer_list constructor via make_unique/make_shared
- details of std::make_index_sequence and std::index_sequence
- Compile c++14-code with g++
- Raw pointer lookup for sets of unique_ptrs
- How can I use C++14 features when building qmake projects?
- Deleted Function in std::pair when using a unique_ptr inside a map
- What changes to C++ made copy initialization work for class with explicit constructor?
- Purpose of perfect forwarding for Callable argument in invocation expression?
- Fallback variadic constructor – why does this work?