gpt4 book ai didi

c++ - 如何在不混淆字段的情况下声明复数?

转载 作者:行者123 更新时间:2023-11-30 01:33:07 24 4
gpt4 key购买 nike

<分区>

我尝试创建复数,但无论出于何种原因,它们总是出现具有虚值的实部和虚部归零。例如,我希望这个小测试应用程序打印 (1,2) 的多个实例,但无论我如何尝试接近它,我得到的都是 (2,0)。

#include "stdafx.h"
#include <complex>
#include <iostream>
using namespace std;
int main()
{
std::complex<double>** complexdouble_c;
complexdouble_c = new std::complex<double>*[5];
for (int i = 0; i < 5; ++i)
complexdouble_c[i] = new std::complex<double>[2];

for (int i = 0; i < 5 && i < 15; i++) {
for (int j = 0; j < 2 && j < 15; j++) {
double real = 1;
double imag = 2;
complexdouble_c[i][j] = (real, imag);
}
}
for (int i = 0; i < 5 && i < 15; i++) {
for (int j = 0; j < 2 && j < 15; j++) {
std::cout << complexdouble_c[i][j];
}
std::cout << "\n";
}
std::complex<double> complexdouble;
double real = 1.0;
double imag = 2.0;
complexdouble = (real, imag);
std::cout << complexdouble;
std::cout << complexdouble.real();
std::cout << complexdouble.imag();
getchar();
}

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