Question: I was wondering how I can initialize a `std::vector` of strings, without having to use a bunch of `push_back`'s in *Visual Studio Ultimate 2012*.

---

I've tried `vector<string> test = {"hello", "world"}`, but that gave me the following error:

> 
> `Error: initialization with '{...}' is not allowed for an object of type "std::vector<std::string, std::allocator<std::string>>`
> 
> 
> 

---

* Why do I receive the error?
* Any ideas on what I can do to store the strings?

Answer: 
**The problem**

You'll have to upgrade to a more recent compiler version (and standard library implementation), if you'd like to use what you have in your snippet.

*VS2012* [doesn't support](http://msdn.microsoft.com/en-us/library/hh567368.aspx) `std::initializer_list`, which means that the overload among `std::vector`'s constructors, that you are trying to use, simply doesn't exist.

In other words; the example cannot be compiled with *VS2012*.

* [**msdn.com** - Support For C++11 Features (Modern C++)](http://msdn.microsoft.com/en-us/library/hh567368.aspx)

---

**Potential Workaround**

Use an intermediate *array* to store the `std::string`s, and use that to initialize the vector.

```
std::string const init_data[] = {
  "hello", "world"
};

std::vector<std::string> test (std::begin (init_data), std::end (init_data));

```
**1. Why do I receive the error?**
Visual Studio 2012 doesn't support list initialization before the [2012 November update](https://support.microsoft.com/en-us/help/2797915/description-of-visual-studio-2012-update-1) according to this [question](https://stackoverflow.com/questions/12654394/initializer-list-not-working-with-vector-in-visual-studio-2012).

**2.Any ideas on what I can do to store the strings?**

Using push\_back() is a totally valid solution. Example:

```cpp
#include<vector>
#include <string>
using namespace std;
int main()
{
    vector<string> test;
    test.push_back("hello");
    test.push_back("world");
    for(int i=0; i<test.size(); i++)
     cout<<test[i]<<endl;
    return 0;
}

```