I get an error that does not match the >> operator in the following function. What's wrong?

void GetarrayElements(int a[]){ int k=0; while (true){ cout <<"to exit just type a value which is above 100 like ex. 101" << endl; cout<< "give me the "<< k <<"th element "; cin >> a[k] >> endl; if (a[k]<=100 && a[k]>=0){ k+=1; } else{ break; } } } 

I am trying to read some input values ​​from 0 to 100 inclusive in an array, and I got this error. "no match for operator ->". What could be wrong?

+4
source share
3 answers

endl can only be applied to output streams such as cout ; you cannot use it on cin .

+11
source

Do not read the read endl element.

Change this:

 cin >> a[k] >> endl; 

... to that:

 cin >> a[k]; 
+5
source
 ostream& endl ( ostream& os ); 

You cannot pass an istream instance (std :: cin in our case) to endl.

+2
source

All Articles