code::blocks 中简单数学的奇怪十六进制答案

Weird hexadecimal answers to simple math in code::blocks

我正在尝试在 C++ 书中完成以下作业。

在 运行 之后:

#include <iostream>

using namespace std;

int main()
{
double first_arg;
double second_arg;

cout << "Enter first argument: ";
cin >> first_arg;
cout << "Enter second argument: ";
cin >> second_arg;

cout << first_arg << " * " << second_arg <<  " = "
     << cout << first_arg * second_arg << "\n";

cout << first_arg << " + " << second_arg << " = "
     << cout << first_arg + second_arg << "\n";

cout << first_arg << " / " << second_arg << " = "
     << cout << first_arg / second_arg << "\n";

cout << first_arg << " - " << second_arg << " = "
     << cout << first_arg - second_arg << "\n";

我得到了一些意想不到的结果。就像这个直接从 windows cli 复制的结果:

Enter first argument: 7
Enter second argument: 9
7 * 9 = 0x6fcc43c463
7 + 9 = 0x6fcc43c416
7 / 9 = 0x6fcc43c40
7 - 9 = 0x6fcc43c4-2

我使用的是具有默认编译器设置的最新版本的代码块。谢谢

cout << first_arg << " * " << second_arg <<  " = "
     << cout << first_arg * second_arg << "\n";

一行中有两个 cout,因为第 1 行没有分号

要解决此问题,请删除第二个 cout 或在每个 cout 语句的第一行末尾添加一个分号。

如果您查看每个答案的最后 2 位数字,您将看到您希望得到的答案,因此它仍然会在指向 cout.[=14= 的指针之后打印出您想要的答案]