如何实现istream :: operator>>(const char& amp;)因为没有这样的函数? [英] How does istream::operator>>( const char& ) as no such function is implemented?

查看:84
本文介绍了如何实现istream :: operator>>(const char& amp;)因为没有这样的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看 istream 文档,您将看到没有函数 istream& operator>>(char&)的实现,但如果编译并运行

 #include< iostream> 

int main(){

char c;

std :: cin>> C;

std :: cout<< c<< std :: endl;

return(0);

}

给予 cin 是类istream的对象,当 std :: cin> gt>时, operator>> 的专业化称为
; c $ c>也实现为非成员函数


istream& operator >>(istream& is,char& c)



Looking at istream documentation, you will see that there is no implementation of function istream &operator>>( char& ), but if you compile and run the code below, it will work just as expected.

#include<iostream>

int main( ) {

  char c;

  std::cin >> c;

  std::cout << c << std::endl;

  return( 0 );

}

Given cin is an object for class istream, which specialization of operator>> is called when std::cin >> c; is executed?

解决方案

operator>> also is implemented as non-member functions.

istream& operator>> (istream& is, char& c)

这篇关于如何实现istream :: operator&gt;&gt;(const char&amp; amp;)因为没有这样的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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