我想就MinGW 4.7.2提出一个问题 我第一次遇到libstdc ++引起的致命问题 - 6.dll当我冒险进入OpenCV时。幸运的是,我遇到了一个解决方法 - > http://answers.opencv.org/question/3740/opencv-243-mingw-cannot-run-program/。一段时间看起来很棒。
现在我正在尝试实现复数。我尝试以下代码
#include <iostream>
#include <complex.h>
using namespace std;
int main(int argc, char* argv[])
{
float _Complex d = 2.0f + 2.0f*I;
cout << "Testing Complex\t" << d;
return 0;
}
一定要运行它。链接时我没有遇到任何错误或警告。我使用CodeBlocks作为Windows中的首选IDE。但是,再一次,我受到了阻碍。这是AppCrash报告
Problem signature:
Problem Event Name: APPCRASH
Application Name: complex.exe
Application Version: 0.0.0.0
Application Timestamp: 515d61f7
Fault Module Name: libstdc++-6.dll
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 4ed82a4d
Exception Code: c0000005
Exception Offset: 000462bc
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
然而令人惊讶的是,How to work with complex numbers in C?提供了一个完美的C代码!
#include <stdio.h> /* Standard Library of Input and Output */
#include <complex.h> /* Standart Library of Complex Numbers */
int main()
{
double complex z1 = 1.0 + 3.0 * I;
double complex z2 = 1.0 - 4.0 * I;
printf("Working with complex numbers:\n");
printf("Starting values: Z1 = %.2f + %.2fi\tZ2 = %.2f + %.2fi\n",creal(z1),cimag(z1),creal(z2),cimag(z2));
double complex sum = z1 + z2;
printf("The sum: Z1 + Z2 = %.2f %+.2fi\n", creal(sum), cimag(sum));
return 0;
}
正如你所看到的那样,错误的libstdc ++ - 6.dll再次发挥作用。有人可以建议我这次有任何解决方法,希望没有降级到以前版本的MinGW,因为我将不得不重建我的所有库。
任何帮助将不胜感激!
答案 0 :(得分:1)
像Jens所说,我不认为complex.h
头文件与C ++兼容。在C ++中,您应该使用complex标题,如下所示:
#include <iostream>
#include <complex>
int main()
{
std::complex<double> c1(1.0,1.0), c2 ;
c2 = pow(c1,2.0);
std::cout << c1 << " " << c2 << std::endl;
}