Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC and std namespace-beginner question

MFC and std namespace-beginner question

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helplearning
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 7 Offline
    7 Offline
    7stud
    wrote on last edited by
    #1

    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?

    A H 2 Replies Last reply
    0
    • 7 7stud

      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?

      A Offline
      A Offline
      Alexandru Savescu
      wrote on last edited by
      #2

      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!

      7 1 Reply Last reply
      0
      • A Alexandru Savescu

        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!

        7 Offline
        7 Offline
        7stud
        wrote on last edited by
        #3

        Thanks, I did that. I'm using VC++ 6.0 if that helps.

        1 Reply Last reply
        0
        • 7 7stud

          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?

          H Offline
          H Offline
          hiseldl
          wrote on last edited by
          #4

          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/

          7 1 Reply Last reply
          0
          • H hiseldl

            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/

            7 Offline
            7 Offline
            7stud
            wrote on last edited by
            #5

            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.

            H 1 Reply Last reply
            0
            • 7 7stud

              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.

              H Offline
              H Offline
              Hosam Aly Mahmoud
              wrote on last edited by
              #6

              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 the std namespace. But, the cmath header file does not contain the std 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 use cmath in Visual C++ 6.0. Hope this helps.

              Hosam Aly Mahmoud

              7 1 Reply Last reply
              0
              • H 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 the std namespace. But, the cmath header file does not contain the std 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 use cmath in Visual C++ 6.0. Hope this helps.

                Hosam Aly Mahmoud

                7 Offline
                7 Offline
                7stud
                wrote on last edited by
                #7

                Thanks for the explanation.

                H 1 Reply Last reply
                0
                • 7 7stud

                  Thanks for the explanation.

                  H Offline
                  H Offline
                  Hosam Aly Mahmoud
                  wrote on last edited by
                  #8

                  You're welcome.

                  Hosam Aly Mahmoud

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups