歌尽桃花

歌尽桃花的动态

歌尽桃花

2013-10-02

哦,C++原来是这么回事儿发表了提问

不好意思,我是初学者。。想问什么时候用>>,什么时候用<<呢,比如cin就用>>

  • Kabe卡芘 2013-10-02 19:55

    回复歌尽桃花:The side effect is to output the right hand variable and the expression produces a value that is an output stream (technically its a reference to an output stream, but it amounts to the same thing). This value can be used again as the left hand size of a &lt;&lt;. So to call the put functions 3 times as before:- cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; "\n"; because the &lt;&lt; operator is evaluated left to right. It take a little getting used to for a FORTRAN programmer, but after a while you get used to seeing this as a cout object with a stream of values flowing into it. As you might expect, input simply reverses the sign on the flow, so to read 3 numbers from the input stream and store them in x, y, z:- cin &gt;&gt; x &gt;&gt; y &gt;&gt; z;

  • 陈良乔 2013-10-24 21:06

    回复歌尽桃花:其实可以形象地来理解这个问题,你可以把箭头的方向看作是数据流动的方向 比如,&gt;&gt;就是数据从左侧流动到右侧,也就是从左侧流出,那么在输入输出过程中,cin或者cout位于我们的左侧,而只有cin是流出(从键盘流出),cout是流入(流入到屏幕) 那么很自然的就是 int n; cin&gt;&gt;n; // 数据从键盘流入变量n cout&lt;&lt;n;// 变量n的数据流入到屏幕   这样记忆就很容易了   很抱歉回答晚了,希望可以帮助到你

  • 歌尽桃花

    2013-10-02

    加入了课程

    哦,C++原来是这么回事儿

    本课程是《我的第一本C++书》的部分精彩章节选集通过本课程和这本书,你可以了解到C++中最核心最重要的内容,可以说,这是一个快速入门C++的课程。都说C++很难,可很多读者在看完这本书后,都有一种恍然...