How can store size of vector first then do Condition??

I cast int value in vector then for vector.size() condition ,do something my condition is if(values.size()==1) in first time always vector.size() is 1,how can wait to get all int value and doesn't //dosomething of this condition quickly after get first int,need an other condition??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vector<int> values;
while(true){
   int key = mySwitch.getReceivedValue();
                values.push_back(key);
                if (values.size() == 1  ) { //not do this in loop quickly wait,maybe vector size is bigger

                    //do something
                                }

                } else if (values.size() > 1 && values.size() <= 7) {
                    //do something else

                } else if (values.size() > 7) {
                    values.clear();
                    continue;
                }
}
Last edited on
don't understand what you want to do, please rephrase.

If the idea is to treat the fist iteration of the loop different, then you may use a flag
1
2
3
4
5
6
7
bool first_time = true;
while(true){
   //...
   if( not first_time and values.size() == 1)
      //...
   first_time = false;
}
Last edited on
hi tnx but my mean is first vector size first maybe 1 maybe 2 if 1 do first condition if 2 second condition,program doesn't wait for get all int value ,with first value do execute
condition
> program doesn't wait for get all int value
¿where it should wait?

perhaps you should get all the input before starting to process
1
2
3
4
5
6
7
//get all input
while( std::cin>>n ){
   v.push_back( n );
}
//process it
if( v.size()==1 )
   //... 
tnx,what can use instead of while() in your code??because I have while(true) loop at the beginning
Topic archived. No new replies allowed.