0

I asked this question earlier and you told me to mention the errors, so I will mention them now(I couldn't figure out how to continue the last thread I started,all I saw was an "add a comment" button and an "answer your question" button, so I had to correct the questio and ask it again, sorry about that):

My question is the following: I'm using visual studio 2010 and I'm writing a win32 application(not a console application). I need to know how to write to a file from this application.

I included these headers: windows.h, stdlib.h, string.h and tchar.h

I wrote a very simple hello world application and it ran just fine.

But when I tried to include iostream and fstream in my project the compiler gave me the following errors.

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(21): error C2039: 'abort' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(21): error C2873: 'abort' : symbol cannot be used in a using-declaration
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2039: 'exit' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2873: 'exit' : symbol cannot be used in a using-declaration
IntelliSense: the global scope has no "abort"   c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib  21  13  
IntelliSense: the global scope has no "exit"    c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib  24  13  

And when I include fstream.h,I get:

error C1083: Cannot open include file: 'fstream.h': No such file or directory   c:\users\user\documents\visual studio 2010\projects\helloworld\helloworld\main.cpp  5   1   helloworld
IntelliSense: cannot open source file "fstream.h" c:\users\user\documents\visual studio 2010\projects\helloworld\helloworld\main.cpp    5   1   helloworld

Same thing for iostream.h

Why are these errors occurring?

Matthieu Rouget
  • 3,289
  • 18
  • 23

4 Answers4

5

In C++, you should use <cstdlib> instead of <stdlib.h>, <cstring> instead of <string.h> (assuming you mean the C style strings. If you want C++ std::string, use <string> [without .h].

And you should use <fstream>, not <fstream.h>.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
1

Please check that your :

#include "stdafx.h"

is the first include of you .cpp file.

Write other includes after this one :

#include "stdafx.h"
#include <iostream>
// ... and so on

int main(...) {

}

... this is a quite frequent mistake with Microsoft compilers (see C++ cout gives undeclared identifier).

Community
  • 1
  • 1
Matthieu Rouget
  • 3,289
  • 18
  • 23
0

Probably you wrote #include "iostream" instead of #include <iostream>

Evgeny Eltishev
  • 593
  • 3
  • 18
0

May be this helps .. Try to Check your errors reasons from

http://msdn.microsoft.com/en-us/library/et4zwx34%28v=vs.80%29.aspx

MAG
  • 2,841
  • 6
  • 27
  • 47