Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting the error no match for operator >> in the following function. What's wrong?

Tags:

c++

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 between 0 and 100 inclusive into an array and i got this error. "no match for operator >>". What can be wrong?

like image 662
Vaios Argiropoulos Avatar asked Dec 03 '22 01:12

Vaios Argiropoulos


2 Answers

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

like image 171
bdonlan Avatar answered Dec 07 '22 23:12

bdonlan


Don't read into the read-only item "endl".

Change this:

cin >> a[k] >> endl; 

...to this:

cin >> a[k];
like image 43
charley Avatar answered Dec 07 '22 22:12

charley