Initializing a vector

Hello, I keep getting an error when I attempt to initialize my vector of strings, v. Any help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "cmath"
using namespace std;

inline void keep_window_open()
{
	cout << "\n\nPlease enter a character to exit: ";
	char ch;
	cin >> ch;
}
int main()
{
	// VARIABLES
	vector<string> v = {"zero", "one", "two", "three"};

	// CODE


	keep_window_open();
}
Last edited on
What compiler (and version) are you using? What error are you getting?

This should work on any C++11 compliant compiler.
I'm using Microsoft Visual C++ 2010 Express.

Here's the error:

error C2552: 'v' : non-aggregates cannot be initialized with initializer list

'std::vector<_Ty>' : Types with a base are not aggregate
with
[
          _Ty=std::string
]
Ah well you're pre C++11, so I don't think you can initialize a vector that way.

See the answer here for another way to do this:
http://stackoverflow.com/q/4268886/2887128
Alrighty will do. Thank you.
FYI, I'm fairly certain you can grab VS2013 Express for free at this point. Or Professional if you have a .edu email address through their DreamSpark program.

I highly recommend getting on a C++11 compiler.
I was just looking into it. I'll try and obtain Professional.
Topic archived. No new replies allowed.