Simple problem with vectors

I'm a CS1 student and we just started using vectors. I'm doing some practice problems from my book to help me better understand vectors. I needed to convert a program that the book had already written from arrays to vectors. When I did I came across this syntax error. I'm not sure how to correct it since this is my first time ever using vectors.

I'm using c++ 11

Here's the error:
|13|error: expected ',' or ';' before '{' token|

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
43
44
45
46
47
48
49
50
51
52
53
54
55
  // This program is a driver that tests a function comparing the
 // contents of two int arrays.
 #include <iostream>
 #include <vector>
 using namespace std;

 // Function Prototype
 bool testPIN(vector <int>, vector <int>);

 int main ()
 {
     const int NUM_DIGITS = 7; // Number of digits in a PIN
     vector<int> pin1 (NUM_DIGITS) {2, 4, 1, 8, 7, 9, 0}; // Base set of values.
     vector <int> pin2 (NUM_DIGITS) {2, 4, 6, 8, 7, 9, 0}; // Only 1 element is different from pin1.

     vector <int> pin3 (NUM_DIGITS){1, 2, 3, 4, 5, 6, 7}; // All elements are different from pin1.


     if (testPIN(pin1, pin2))
        cout << "ERROR: pin1 and pin2 report to be the same.\n";
        else
        cout << "SUCCESS: pin1 and pin2 are different.\n";

     if (testPIN(pin1, pin3))
        cout << "ERROR: pin1 and pin3 report to be the same.\n";
        else
        cout << "SUCCESS: pin1 and pin3 are different.\n";

     if (testPIN(pin1, pin1))
        cout << "SUCCESS: pin1 and pin1 report to be the same.\n";
        else
        cout << "ERROR: pin1 and pin1 report to be different.\n";

        return 0;
 }


//******************************************************************
 // The following function accepts two int arrays. The arrays are *
 // compared. If they contain the same values, true is returned. *
 // If they contain different values, false is returned. *
 //******************************************************************

 bool testPIN(vector<int> custPIN, vector <int> databasePIN)
 {


     for (int index = 0; index < databasePIN.size(); index++)
     {
         if (custPIN[index] != databasePIN[index])
         return false; // We've found two different values.
     }
     return true; // If we make it this far, the values are the same.
 }
1
2
3
  vector<int> pin1 (NUM_DIGITS) {2, 4, 1, 8, 7, 9, 0}; // Base set of values.
     vector <int> pin2 (NUM_DIGITS) {2, 4, 6, 8, 7, 9, 0}; // Only 1 element is different from pin1.
     vector <int> pin3 (NUM_DIGITS){1, 2, 3, 4, 5, 6, 7}; // All elements are different from pin1. 


It should be :
1
2
3
4
     vector<int> pin1 {2, 4, 1, 8, 7, 9, 0}; // Base set of values.
     vector <int> pin2 {2, 4, 6, 8, 7, 9, 0}; // Only 1 element is different from pin1.

     vector <int> pin3 {1, 2, 3, 4, 5, 6, 7}; // All elements are different from pin1. 
I'm getting this error:


|13|error: in C++98 'pin1' must be initialized by constructor, not by '{...}'|
|13|error: in C++98 'pin1' must be initialized by constructor, not by '{...}'|

You are using C++11, not C++98

TheEurekaMan wrote:
I'm using c++ 11
Yup that's why I'm confused.
Oh nevermind. I went back to check my settings and my compiler wasn't set to C++ 11. I think it's because I switched the colors recently and as a result my compiler settings reset. It works now, thanks!
Topic archived. No new replies allowed.