cout和cin不是功能,那么它们是什么? [英] cout and cin are not functions, so what are they?

查看:83
本文介绍了cout和cin不是功能,那么它们是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常使用C编程语言,我们认为printf和scanf是函数. 当涉及到cout和cin时,在C ++中它们是什么?我的意思是它们不能是函数,因为它们后面没有括号,因此它们不是函数. 那么标准输入和输出函数是cout和cin是什么?还是其他?

Generally in C programming language We consider printf and scanf to be functions. when it comes to cout and cin, in C++ what are they?I mean they cant be functions as they are not followed by parenthesis,so they are not functions. So what are cout and cin are standard input and output functions?OR something else?

推荐答案

std::cout std::cin 是类 操作符重载 .

std::cout and std::cin are global objects of classes std::ostream and std::istream respectively, which they've overloaded operator << and >>. You should read about operator overloading.

   cout    <<      expr  ;
  ~~~~~~  ~~~~   ~~~~~~~~
  object   op.   argument 

这就像一个函数调用;该函数是一个重载运算符,并且是此操作的快捷方式:

It's like a function call; the function is an overloaded operator and a shortcut for this:

cout.operator<<(expr);

或者这个:

operator<<(cout, expr);

取决于重载解决方案的结果

depending on the results of overload resolution

这篇关于cout和cin不是功能,那么它们是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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