-
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//
-
Forgot to mention
I am using VC++6 on NT4, with the latest service pack for VC & NT4
THX,
John D..
-
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.
-
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..
-
do not use
#include "fstream.h"
the namespace std is used in the headers without '.h'
use
#include "fstream"
-
>>> #include "fstream"
#include <fstream>
-
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..
-
reorder include files:
#include "stdafx.h"
#include "afxinet.h"
#include "fstream"
and if you include the 'windows.h' in your stdafx.h - comment it.
-
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.
-
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..
-
>>> 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.
-
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
-
its real simple really....
#include<> looks in the compilers standard include directory.
#include"" looks in your apps current directory