开发者

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

开发者 https://www.devze.com 2023-03-22 00:06 出处:网络
void GetarrayElements(int a[]){ int k=0; while (true){ cout <<\"to exit just type a value which is above 100 like ex. 101\" << endl;
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 <&l开发者_StackOverflow社区t;"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?


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


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

Change this:

cin >> a[k] >> endl; 

...to this:

cin >> a[k];


ostream& endl ( ostream& os );

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

0

精彩评论

暂无评论...
验证码 换一张
取 消