using std problem

This is a discussion on using std problem within the C++ Programming forums, part of the General Programming Boards category; Whenever i'm trying to use the std C header files with the using statement in a C++ project with Visual ...

  1. #1
    Registered User trekker's Avatar
    Join Date
    Mar 2002
    Posts
    46

    using std problem

    Whenever i'm trying to use the std C header files
    with the using statement
    in a C++ project with Visual Studio i get an error at compile time
    e.g.

    Code:
    ...
    #include <cstring>
    
    using std::strlen;
    ...
    
    ...strlen( s )...
    i want to use this type of using statement
    so not to mess up a lot the namespace of my project.

    the compile error says that the strlen() func is not a member
    of the std namespace.
    How could this be possible? Doesn't MS follow the C++ standard?

    As you've probably guessed this is one the first times that i use
    VS and i'd like to be the last also...

    TIA
    to boldy code where...

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    You are using VS 6.0,right?
    IIRC in this VS release cstring,ctime and so on are not in the std namespace.
    Try maybe this
    Code:
    namespace std
    {
    #include <cstring>
    }

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >> Doesn't MS follow the C++ standard?
    Not as closely as it should.

    You can do what Wledge said, or just ignore the std:: prefix.

    To make the code portable, try this:
    Code:
    #ifdef _MSC_VER
    #if _MSC_VER < 1300
    namespace std {
    #endif
    #endif
    
    #include <cstring>
    // and whatever things like ctime, etc, that don't have the std namespace in MSVC
    
    #ifdef _MSC_VER
    #if _MSC_VER < 1300
    }
    #endif
    #endif
    Last edited by XSquared; 06-07-2003 at 01:47 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571

    Re: using std problem

    Originally posted by trekker

    How could this be possible? Doesn't MS follow the C++ standard?
    You're using Visual Studio 6 or earlier; that code would work fine on newer VC++ compilers. The main reason it's not standard is that your compiler is older than the standard itself.

    The next version (.NET 2002) was 99% compliant with the standard, and the few discrepencies have been resolved for .NET 2003.

  5. #5
    Registered User trekker's Avatar
    Join Date
    Mar 2002
    Posts
    46
    thanks for your answers
    your solutions worked fine
    it's obvious that I'm using VS 6.0

    I've previously tried to use the __MSDOS__ predefined constant
    but it didn't work. Any suggestions?
    to boldy code where...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in calling DLL
    By bhagwat_maimt in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 09:43 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. array problem?
    By ssjnamek in forum C Programming
    Replies: 14
    Last Post: 02-08-2006, 05:03 PM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. Problem with std lists and my ships
    By Vorok in forum Game Programming
    Replies: 1
    Last Post: 01-15-2003, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21