C++ 输出顺序

标签 c++ cout

我有这样的语句,旨在输出函数返回的内容。

std::cout<<"result: " << calculateAvg(someArray, size) << std::endl;

然而,该函数在返回值之前会自行输出内容。有没有办法让我打印出该行返回的内容,而不是在函数打印的所有内容之后?

最佳答案

Is there a way for me to print out what is returned on that line, instead of after everything that is printed by the function?

没有。该函数必须先运行才能返回某些内容。这意味着函数输出的任何输出都将出现在函数返回值的输出之前。

关于C++ 输出顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34886909/

相关文章:

c++ - 以相反顺序打印数组,意外输出 (c++)

C++ 串联哎呀

c++ - 崇高文本3 : SublimeLinter: c disabled ("cppcheck" cannot be found)

C++ 自动舍入

c++ - shared_ptr::reset 仅适用于原始指针?

c++ - 如何获取不以空格结尾的字符串的输入?

c++ - Windows/C++/HelloWorld 中的 Eclipse - 启动进程时出错。无法运行程序 "C:..\Hello World\src\Hello World.cpp": Launching failed

c++ - swig 使用变量扩展模板类

c++ - cout 不向控制台打印任何内容

c++ - void Print(vector<string>) 函数不打印