Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ostream:如何为这个链式输出调用函数?_C++ - Fatal编程技术网

C++ ostream:如何为这个链式输出调用函数?

C++ ostream:如何为这个链式输出调用函数?,c++,C++,有人能解释一下下面的iostreamcout代码是如何使用每个特定函数(包括其声明)进行计算的吗?另外,hex操纵器如何修改流标志(我猜它调用ios.flags())。例如,我正在查看并对所调用的内容和评估顺序感到困惑(我认为没有指定的顺序) #包括 使用名称空间std; int main() { int v=0xFF; coutstd::hex和std::endl是独立函数,分别以std::ios\u base&和std::basic\u ostream&作为输入: std::ios\u ba

有人能解释一下下面的iostream
cout
代码是如何使用每个特定函数(包括其声明)进行计算的吗?另外,
hex
操纵器如何修改流标志(我猜它调用
ios.flags()
)。例如,我正在查看并对所调用的内容和评估顺序感到困惑(我认为没有指定的顺序)

#包括
使用名称空间std;
int main()
{
int v=0xFF;

cout
std::hex
std::endl
是独立函数,分别以
std::ios\u base&
std::basic\u ostream&
作为输入:

std::ios\u base和hex(std::ios\u base和str);
模板
std::basic_ostream&endl(std::basic_ostream&os);
这些函数根据需要操纵给定流:

  • std::hex()
    调用流的
    setf()
    方法来启用流上的
    std::ios\u base::hex
    标志
  • std::endl()
    将换行符写入流,然后刷新流

std::basic_ostream
具有非静态成员
运算符在不了解您的特定环境的情况下,这里的任何人所能做的最好的事情就是猜测正在进行的实际调用。您最好的选择可能是使用调试器并逐步执行代码,包括逐步执行函数。尽管计算顺序定义良好(相当于
((虽然它只能从c++17中很好地定义)。@StephenNewell基于此,我的怀疑是
ostream&operator@notaorb是的,事情就是这样
#include <iostream>
using namespace std;

int main()
{
    int v = 0xFF;
    cout << "0x" << hex << v << endl;

    return 0;
}