gpt4 book ai didi

C++ << >> 运算符

转载 作者:搜寻专家 更新时间:2023-10-31 00:21:18 25 4
gpt4 key购买 nike

我可以使用例如 <<运算符(operator)按如下方式输入我的名字:

std::cout<<"My name is: "<<name<<std::endl;

关于 Wikipedia它提到以下关于 << 的内容和 >> :

In the context of iostreams, writers often will refer to ​<< ​ and ​>>​ as the “put-to” or "stream insertion" and “get-from” or "stream extraction" operators, respectively.

在上面的示例代码中,不是 <<执行串联concatenation 在 C++ 中是否有特殊的运算符?

谢谢。

最佳答案

C++ 中没有特殊 运算符。 std::ios (它的派生)被滥用 operator>>operator<<为了提供一种执行流操作的简单方法:这两个运算符在 C++ 中具有不同的语义。

用于连接两个 std::string 的运算符是operator+ (但我认为在这种情况下,他们没有滥用它:两个字符串之间的 operator+ 正在做我期望的事情)。

关于C++ << >> 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4803736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com