MFC and std namespace-beginner question
-
I need to use the sqrt() function in in one of my functions in a Windows program using MFC. At the top of the file I put in these lines:
#include <cmath> using std::sqrt;
and I got this error:error C2653: 'std' : is not a class or namespace name
Why doesn't the compiler recognize the std namespace? -
I need to use the sqrt() function in in one of my functions in a Windows program using MFC. At the top of the file I put in these lines:
#include <cmath> using std::sqrt;
and I got this error:error C2653: 'std' : is not a class or namespace name
Why doesn't the compiler recognize the std namespace?It's odd that it does not work. As a workaround, use the C-standart function.
#include <math.h> ... double x = sqrt (y);
Best regards, Alexandru Savescu P.S. Interested in art? Visit this! -
It's odd that it does not work. As a workaround, use the C-standart function.
#include <math.h> ... double x = sqrt (y);
Best regards, Alexandru Savescu P.S. Interested in art? Visit this! -
I need to use the sqrt() function in in one of my functions in a Windows program using MFC. At the top of the file I put in these lines:
#include <cmath> using std::sqrt;
and I got this error:error C2653: 'std' : is not a class or namespace name
Why doesn't the compiler recognize the std namespace?Try: #include <cmath> using namespace std; ... // use the sqrt func float x = sqrt(y); or you can just call the sqrt function without the "using" keyword: #include <cmath> ... // use the sqrt func float x = std::sqrt(y); HTH. David Hisel -- http://www.hisel.com/
-
Try: #include <cmath> using namespace std; ... // use the sqrt func float x = sqrt(y); or you can just call the sqrt function without the "using" keyword: #include <cmath> ... // use the sqrt func float x = std::sqrt(y); HTH. David Hisel -- http://www.hisel.com/
I tried both of those, but as expected, I get the same error--my compiler does not recognize "std" as a namespace. My compiler does recognize "std" as a namespace for win32 console apps, but not this, my first win32 with MFC app attempting to use the std namespace.
-
I tried both of those, but as expected, I get the same error--my compiler does not recognize "std" as a namespace. My compiler does recognize "std" as a namespace for win32 console apps, but not this, my first win32 with MFC app attempting to use the std namespace.
The things I will say in this reply are MS Visual C++ 6.0 specific. I have not tried them on any other compiler. 7stud wrote: My compiler does recognize "std" as a namespace for win32 console apps You probably use
#include <iostream>
, which includes thestd
namespace. But, thecmath
header file does not contain thestd
namespace. In fact, the following code is perfectly legal:#include <cmath>
int main() {
double x = sqrt(5);
}But this one is not:
#include <cmath>
using std::sqrt;So you don't need to use the
std
namespace if you are going to usecmath
in Visual C++ 6.0. Hope this helps.Hosam Aly Mahmoud
-
The things I will say in this reply are MS Visual C++ 6.0 specific. I have not tried them on any other compiler. 7stud wrote: My compiler does recognize "std" as a namespace for win32 console apps You probably use
#include <iostream>
, which includes thestd
namespace. But, thecmath
header file does not contain thestd
namespace. In fact, the following code is perfectly legal:#include <cmath>
int main() {
double x = sqrt(5);
}But this one is not:
#include <cmath>
using std::sqrt;So you don't need to use the
std
namespace if you are going to usecmath
in Visual C++ 6.0. Hope this helps.Hosam Aly Mahmoud
-
You're welcome.
Hosam Aly Mahmoud