#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
double x = 5;
double y = 10;
double z = max(x, y);
cout << z;
return 0;
}
Thanks for your help.
Trouble with max()
Does anyone else have any idea why this C++ code snippet doesn''t seem to want to compile? I keep getting this compiler error.
C:\Programming\Learn\Learn1\Learn1.cpp(12) : error C2065: ''max'' : undeclared identifier
i dont think the macro max is defined, its what it says. Include windows.h or make a max macro.
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
quote:Original post by Daivam
Isn''t max() defined in the algorithm header file though?
Yes, it is defined in
algorithm
.Are you sure that in the code that you are compiling you actually put:
using namespace std;
as the error may come as a result of
max()
not being qualified. [ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
Maybe I''ve never tried it before without the .h at the end, but doesnt it need to be:
#include <algorithm.h>
#include <iostream.h>
?
Phosphorous
#include <algorithm.h>
#include <iostream.h>
?
Phosphorous
quote:Original post by phosphorous
Maybe I''ve never tried it before without the .h at the end, but doesnt it need to be:
#include <algorithm.h>
#include <iostream.h>
?
Phosphorous
No! It should definitely be
algorithm
and iostream
, i.e. without the .h
extension. [ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
quote:Original post by Daivam
Isn''t max() defined in the algorithm header file though?
MS define min and max macros, so they leave them out of algorithm. Consult the MSDN documentation for further details.
quote:Original post by Lektrixquote:Original post by phosphorous
Maybe I''ve never tried it before without the .h at the end, but doesnt it need to be:
#include <algorithm.h>
#include <iostream.h>
?
Phosphorous
No! It should definitely bealgorithm
andiostream
, i.e. without the.h
extension.
Oops! You are absolutely right. I didn''t look close enough to realize that he needed to use STL headers. Guess I shouldn''t post before my morning Mt.Dew
you could always open up the header file and look through the macros and function prototypes to see what you have available.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement