xoring values from vector?

Feb 26, 2013 at 2:31am
Ok so im trying to xor values from the vector but im not sure how to go about doing it?

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 <vector>

using namespace std;

int main()
{
    vector<int> vars;

    int num;
    int result;
    int number = 1;

    while(num != -1)
    {
        cout << "enter value #" << number++ << endl;
        cin >> num;
        vars.push_back(num);
    }

    cin.get();
    return 0;
}
Feb 26, 2013 at 2:37am
What are you supposed to XOR? XOR takes two operands. You're implying the entries in the vector are one of the two numbers. What is the other?

BTW, at line 14 num is uninitialized. You could skip the whole loop if memory happens to contain -1.
Feb 26, 2013 at 2:37am
xor needs another value after the operator:

34 ^ 89

cout << (vars.at(x) ^ 12) << endl;
Topic archived. No new replies allowed.