gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:11:22 25 4
gpt4 key购买 nike

我正在尝试在 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 的指针之后打印出您想要的答案。

关于c++ - code::blocks 中简单数学的奇怪十六进制答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32939536/

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