C++的CIN和COUT操作符 C++中的CIN和COUT是两个操作符(operator),且是左操作符,相同于+, -等操作符,而且与这些操作符一样,返回的表达式值为左值。看下面这个例子:
#include <iostream.h> int main(int argc, char **argv) { std::cout << "Enter two numbers: " << std::endl; int v1, v2; std::cin >> v1 >> v2; std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl; return 0; } 在第7行CIN的例子中,前面的std::cin >> v1表达式表示从cin中读入一个值,赋给v1,表达式左操作数(left-hand operand)为std::cin,右操作数为(right-hand operand),表达式返回左操作值,即std::cin,于是第7行相当于下面两行: std::cin >> v1; std::cin >> v2; 与CIN类似,COUT也是左操作符,第9到10行的解释与上面类似。
本文转自:翔宇亭——IT乐园
|
|