首页 > 解决方案 > Gcc 无法识别“双复数”减速

问题描述

我需要一个复杂的库来存放 c++ 或 c 中的一些东西。

所以我在linux中找到了一些有用的工具提示。

man complex 

文档有这样的好例子:

#include <math.h>        /* for atan */
#include <stdio.h>
#include <complex.h>

int
main(void)
{
   double pi = 4 * atan(1.0);
   double complex z = cexp(I * pi);
   printf("%f + %f * i\n", creal(z), cimag(z));
}

一切顺利...

但我每次尝试都出错。

> Executing task: /usr/bin/g++ -g '/home/max/Documents/c_expls/test2.cpp' -o '/home/max/Documents/c_expls/test2' <

/home/max/Documents/c_expls/test2.cpp: In function ‘int main()’:
/home/max/Documents/c_expls/test2.cpp:10:17: error: expected initializer before ‘z’
   10 |  double complex z = cexp(I * pi);
      |                 ^
/home/max/Documents/c_expls/test2.cpp:11:32: error: ‘z’ was not declared in this scope
   11 |  printf("%f + %f * i\n", creal(z), cimag(z));
      |                                ^
The terminal process "/bin/bash '-c', '/usr/bin/g++ -g '/home/max/Documents/c_expls/test2.cpp' -o '/home/max/Documents/c_expls/test2''" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

我编辑了一点代码,比如添加double complex z等..但同一台机器......同样的错误......

我认为我的 gcc 安装缺少组件。因为我试过 Code::Blocks

你有什么想法,为什么我的 gcc 不知道这个声明?

标签: cgcc

解决方案


您需要编译gcc并指定要使用 C99 标准或更高版本-std=c99

对于 C++,使用std::complex.


推荐阅读