user6305027
user6305027

Reputation:

How to use vectors in C++ using Xcode 7.3?

I'm studying from Bjarne Stroustroup's Programming Principles and Practice Using C++ (Second Ed.) At the moment I'm stuck at the vectors chapter, because of this error message in the Terminal:

fourth19.cpp:15:23: error: non-aggregate type 'std::vector<int>' cannot be
  initialized with an initializer list
std::vector <int> v = {5, 7, 9, 4, 6, 8};    //vector of 6 ints

My/his code looks like this:

std::vector <int> v = {5, 7, 9, 4, 6, 8};    //vector of 6 ints
std::cout<<v[0];

I didn't find anything that explains how to do this with Xcode 7+.

So if you have Xcode 7+ please write me down what to change and where to change that.

Upvotes: 0

Views: 778

Answers (1)

marko
marko

Reputation: 9169

The default compiler flags for new Xcode projects is -std=gnu++11.

To check this:

1: Select your project in the Project Navigator (left-hand side of window, (Option-1 shows it if hidden). It's the top item in the tree.

2: To the left of the search field, ensure that 'All' is selected rather than 'Basic'

3: Search for 'C++ Language Dialect' in the settings view.

4: It'll be in the section 'Apple LLVM 7.1 Language - C++'

Upvotes: 1

Related Questions