<< and>> in C++

后端 未结 5 1031
走了就别回头了
走了就别回头了 2020-12-07 03:45

I don\'t quite understand what this means...I\'m just learning C++ from my very very very basic Python experience...and so this may be a very stupid question. My question i

5条回答
  •  爱一瞬间的悲伤
    2020-12-07 04:28

    Instead of saying

    print "Hello" + "world"  #I know, you wouldn't actually do it like this.
    

    where "print" is the command and "hello world" is your text,

    c++ works as

    cout << "Hello" << "World";  // or like this. But...
    
    int i = 42;
    cout << "The answer is: " << i;  //you may want to do this
    

    c++ uses "cout" as the command and "<<" as a joiner, or, more technically, an operator used on the out stream.

    cin works similarly where the >> is just an operator that works on the in stream.

提交回复
热议问题