MinGW 错误:'min'不是 'std' 的成员

MinGW error: 'min' is not a member of 'std'

本文关键字:std 成员 不是 min 错误 MinGW      更新时间:2023-10-16

我试图仅使用标准库将一些VC++6代码转换为控制台应用程序,但从MinGW(代码::Blocks 10.05 IDE提供的任何版本(收到以下错误:

error: 'min' is not a member of 'std'

这与以下代码行有关:

L.Precision=std::min(1.e-4,0.001*res);

L.Precisiondouble并且resdouble。以前这条线是:

L.Precision=min(1.e-4,0.001*res);

但这给出了一个错误:

error: 'min' was not declared in this scope

以下是有问题的文件中的标题:

#include<stdio.h>
#include<math.h>
//#include<algorithm.h>
#include <malloc.h>
#include "complex.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"

我知道这可能与文件windef.h中定义的一些宏有关,但如果我错了,请纠正我。

我该怎么办?我对C++还比较陌生,甚至不确定windef.h在哪里被调用。例如,我认为这只是每个windows程序所需要的,并且是由MinGW在某个时候添加的。我希望最终的代码是跨平台的。

您应该取消注释并修复#include <algorithm>(不带.h(,std::min就是在这里声明的。

这与MinGW、GCC或Windows完全无关,这是标准的C++。如果遇到任何其他类似错误,请在上搜索丢失的标识符http://en.cppreference.com/w/.

另外:使用<cmath><cstdio>,避免使用malloc和朋友,使用new/new[]delete/delete[]