Vectors in a teachers code

So my teacher gave me this code to study over the week and im going to have a test. He's not the most helpful and I can't get it to compile. I have an error immediately with the vectors. Can you even set vectors like this? Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 /* Vector examples
Written by Bernhard Firner
*/
#include <iostream>
#include <vector>
using std::vector;
using std::cout;
int main(int argc, char** argv) {
 vector<int> a = { 1, 2, 3, 4 };
 vector<int> b = { 1, 2, 3, 4 };
 vector<int> c = { 1, 2, 3, 4 };
 if (a == b) {
  cout << "a is equal to b!\n";
 }
 if (a == c) {
  cout << "a is equal to c!\n";
 }
 //Copy an existing vector (copy constructor)
 //The first argument sets the size of the new vector
 //The second argument sets the default value of each item
 vector<int> d(10, 5);
 //Insert all of a into d
 d.insert(d.end(), a.begin(), a.end());
 d.erase(d.begin(), d.begin() + 5);
 d.push_back(25);
 if (d == a) {
  cout << "d and a are equal!\n";
 }
 for (int i = 0; i < d.size(); ++i) {
  cout << d[i] << '\n';
 }
 //A two-dimensional vector with 5 rows, 2 columns, all values are 42
 vector<vector<int>> twod(5, vector<int>(2, 42));
 /*
 for (int i = 0; i < twod.size(); ++i) {
  for (int j = 0; j < twod.at(i).size(); ++j) {
   cout << twod.at(i).at(j) << ' ';
  }
  cout << '\n';
 }
 */ }
Last edited on
Please post the complete error messages exactly as they appear in your development environment.

And please state what compiler you're using along with the exact version of that compiler. If you're working with an IDE please state which one you're using.

Last edited on
Did you compile with -std=c++11 flag?
hmm..... I don't know which flag? I can't compile period on visual studio 2010
A flag is not going to help you with VS2010.

The initialization syntax at lines 9-11 was added in C++11. You're going to need a more recent compiler that supports C++11 syntax.
Topic archived. No new replies allowed.