`istream :: get`和`operator>>>(istream& char&)的区别 [英] Difference between `istream::get` and `operator>>(istream&, char&)`

查看:137
本文介绍了`istream :: get`和`operator>>>(istream& char&)的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 istream :: get operator>>(istream& char;&)

  char ch; 
cin.get(ch);
cin>> ch;您可以解释阻止1 无效的可能原因, 块2 有效

  cin.get()。get * 
char ch;
cin.get(ch).get(ch); //不给出错误**块2 **

我的猜测是:



块1相当于 cin> >> ;; while block 2 cin>> ch>> ch;

解决方案

istream :: get(char c)返回 istream& ,而其他无参版本返回int。



因此,在第二个版本中,您可以通过 istream& 这是完全合法的,而在第一个尝试调用方法get的不合法 int


What is the difference between using istream::get and operator>>(istream&, char&):

char ch;    
cin.get(ch);
cin>>ch;

Can you explain the possible reason block 1 is invalid while block 2 is valid

cin.get().get();//Error **block 1**
char ch;
cin.get(ch).get(ch);//Doesn't gives an error  **block 2**

My guess would be:

block 1 is equivalent to cin>> >>; while block 2 cin>>ch>>ch;

解决方案

istream::get(char c) returns an istream&, while the other no-argument version returns int.

So in the second version you invoke .get(ch) over an istream& which is perfectly legal, while in the first one you attempt to call method get of an int which is not legal.

这篇关于`istream :: get`和`operator>>>(istream& char&)的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆