c - 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 不知道这个声明?
解决方案
您需要编译gcc
并指定要使用 C99 标准或更高版本-std=c99
。
对于 C++,使用std::complex
.
推荐阅读
- visual-studio-2015 - 构建实用程序并在另一个项目的预构建中执行它
- python - 有没有办法根据条件将列表“分叉”成两个
- postgresql - 将文本值(6/1/2018 11:34:33 PM、6/2/2018 2:32:07 AM)转换为时间戳
- angular - Angular 6:OnChanges 不适用于异步管道
- c++ - PCL shared_ptr的垃圾收集?
- javascript - 如果我使用地图而不是静态组件,则路线会重新呈现
- php - 在 Symfony 中而不是在控制器中使用服务的最佳实践是什么?
- c# - SignInManager.PasswordSignIn 在第一次尝试时很慢
- javascript - JavaScript 替换字符串中的特定单词
- sql-server - SQL Server System.OutOfMemoryException