Thread: Help please I still suck

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Help please I still suck

    Code:
    #include <ctime>
    
    void sleep(double secs);
    
    int main()
    {
    	sleep(5);
    
    	return 0;
    }
    
    void sleep(double secs)
    { 
        using namespace std;
        clock_t end_time = clock() + clock_t(secs*CLOCKS_PER_SEC);
        while (clock() < end_time);
    }
    Error:
    error C2871: 'std' : does not exist or is not a namespace
    Using MSVC++ and winxp

    Thanks

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    VC++ doesnt seem to do what's expected and put the functions and structs in time.h into namespace std.........but as all of the old C headers should be in both global scope and inside the std namespace, you can do without it in this instance if you wish....So drop the using line and it will work

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    simple
    Code:
    #include <ctime>
    using namespace std; // move it here
    
    void sleep(double secs);
    
    int main()
    {
    	sleep(5);
    
    	return 0;
    }
    
    void sleep(double secs)
    { 
        
        clock_t end_time = clock() + clock_t(secs*CLOCKS_PER_SEC);
        while (clock() < end_time);
    }
    I guess it depends on your compiler as well becuase i tried your original code and it worked fine. I also tried the way i am telling you. They both work no errors

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    It was acceptable for face_master to use the "using" statement inside a block and not globally

    The problem was with VC++6's <ctime> header


    #if _MSC_VER > 1000
    #pragma once
    #endif

    #ifndef _CTIME_
    #define _CTIME_
    #ifdef _STD_USING
    #undef _STD_USING
    #include <time.h>
    #define _STD_USING
    #else
    #include <time.h>
    #endif /* _STD_USING */
    #endif /* _CTIME_ */

    /*
    * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
    * Consult your license regarding permissions and restrictions.
    */
    Note that it doesnt mention namespace std...that's whats giving the error - refering to a namespace that hasnt been defined.

    Also not the date of this header......quite a while before the standard was finished....that's probably the real problem here as I think I read somewhere that namespaces were a late addition to the standard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Spoilers suck!
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 07-31-2008, 09:18 PM
  2. amd stock fans suck!!
    By Kinasz in forum Tech Board
    Replies: 25
    Last Post: 05-05-2004, 09:14 AM