comparing an input value with vector won't work, any work around?

Is there a workaround with this?
1
2
3
4
5
6
7
vector <int> size1{ 1,2,3,4,5,6,7,8,9 };
		std::cin >> input;

		if (input == size1)
			{
                       //cout something
			}

Sure one could say I could do something like:
 
if(input == 1 || 2 || 3) 

etc...

But I wanna push back values into the vector if it is true. Btw to be more clear I'm trying to make it if input is equal to any one of those elements in the vector

Any solution?
std::find http://www.cplusplus.com/reference/algorithm/find/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// find example
#include <iostream>     // std::cout
#include <algorithm>    // std::find
#include <vector>       // std::vector

int main () {
  std::vector<int> size1 {1,2,3,4,5,6,7,8,9};
  int input {};
  std::cin >> input;
  auto it = find( size1.begin(), size1.end(), input );
  if ( it != size1.end() ) {
    std::cout << input << " is in size1\n";
  }
}
Hello possum swallower,

Actually none of it is cleae.

Do you want to add to the vector is an entered number does not exist?

How about:
1
2
3
4
5
6
7
8
9
10
11
vector <int> nums{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };

std::cin >> input;

for (size_t idx = 0; idx < nums.size(); idx++)
{   
    if (input == nums[idx])
    {
        // Do something.
    }
}

Beyond that I am not sure what you are trying to do.

Andy
@Handy Andy I remember you from my last question lol, all I am trying to achieve is to compare the cin and vector in the if statement, the rest I'm able to do from there. But that really makes it clearer for me .
Hello possum swallower,

Glad that makes sense.

Either method will achieve the same result.

Andy
Topic archived. No new replies allowed.