using namespace error

This is a discussion on using namespace error within the Windows Programming forums, part of the Platform Specific Boards category; Hello, When I try to complie the following code i get :- "error C2871: 'std' : does not exist or ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    19

    Unhappy using namespace error

    Hello,

    When I try to complie the following code i get :-

    "error C2871: 'std' : does not exist or is not a namespace"
    &
    "error C2065: 'ofstream' : undeclared identifier"


    #include "fstream.h"
    #include "stdafx.h"
    #include "afxinet.h"
    using namespace std;

    int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {

    ofstream logfile;
    return 0;

    }

    TIA,
    John D//

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    19

    Forgot to mention

    I am using VC++6 on NT4, with the latest service pack for VC & NT4

    THX,
    John D..

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I think you should check out your understanding of the #include directive, in particular, the difference between...

    #include "file"

    ...and...

    #include <file>

    I don't know if you have legitimate reasons for doing what you have done, I can only see the code you have posted, but it certainly looks to me as if you are using the wrong one.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    19
    Thanks for the reply.

    I tried;

    #include <fstream.h>
    #include <stdafx.h>
    #include <afxinet.h>

    as well but still have the same problem.

    John d..

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    do not use
    #include "fstream.h"

    the namespace std is used in the headers without '.h'

    use
    #include "fstream"

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> #include "fstream"

    #include <fstream>
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    19
    Ok, Tried that as well with the same result.

    the reason i was using namespace std; was to get around the original problem.

    error C2065: 'ofstream' : undeclared identifier.

    Am I doing something fundamentaly wrong here.

    ofstream is part of a ftp app which compiles ok. It only when I try to use ofstream, I am getting compile errors.

    John D..

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    reorder include files:

    #include "stdafx.h"
    #include "afxinet.h"
    #include "fstream"

    and if you include the 'windows.h' in your stdafx.h - comment it.

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You need to use...

    #include <fstream>
    using namespace std;

    Is that what you've got?

    damyan:

    Unless he has moved his standard include files, using the "file" version of the #include directive will not work.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User
    Join Date
    Aug 2001
    Posts
    19

    Thanks

    Using

    #include "stdafx.h"
    #include "afxinet.h"
    #include <fstream>
    using namespace std;

    has worked!! Im getting 3 warnings however

    LINK : warning LNK4089: all references to "ADVAPI32.dll" discarded by /OPT:REF
    LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
    LINK : warning LNK4089: all references to "comdlg32.dll" discarded by /OPT:REF


    But its compiling.

    Thanks for all your help.

    John D..

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> has worked!!

    Okay, but...

    >>>
    I think you should check out your understanding of the #include directive, in particular, the difference between...

    #include "file"

    ...and...

    #include <file>
    <<<

    ... just blindly accepting a snippet that worked will not help you solve your other problem. This is for your own good - I'm not just being difficult. <file> and "file" are not the same, indeed <file.h> and <file> are not the same either.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Registered User
    Join Date
    Aug 2001
    Posts
    19

    Fair Enough

    Thats a fair enough comment. My back was against the wall at the time of posting. I needed to get something up and running very quickly.

    Now that I have some spare time I'll be reading up on the include statement.

    Thanks,
    JohnD

  13. #13
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    its real simple really....

    #include<> looks in the compilers standard include directory.
    #include"" looks in your apps current directory
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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