You are here:

C++/fatal error in c++

Advertisement


Question
QUESTION: #include<iostream.h>
void m1(int *a){
 
a = new int[20];

a[0] = 100;

}
void m2(int *a){

  a = new int[20];

  a[0] = 200;

  delete[] a;

}

int main()
{
 int *a = new int [20];
 a[0] = 20;

cout<<a[0];

 m1(a);

 cout<<a[0];

 m2(a);

 cout<<a[0];

return 0;
}
in the above code i am getting fatal error during compilation : "Must use c++ for type iostream" my file has extension c++ still the error.pls help. thanx

ANSWER: <iostream.h> is not a standard C++ header.

Use #include <iostream> instead. You may want to add  using namespace std ; after that so that you could use just cout instead of std::cout.

See http://cplusplus.com/reference/ for a list of standard C++ headers.

Also See: http://forum.codecall.net/c-tutorials/25565-using-namespace-std.html

 

---------- FOLLOW-UP ----------

QUESTION: after replacing "#include<iostream.h>" by "#include<iostream> using namespace std;" it is showing error "unable to open include file IOSTREAM"

ANSWER: It appears that you are either using an obsolete, non-standard, C++ compiler or there is a problem with the installation.

Could you tell me the name and the version of the compiler you are trying to use? Also the platform (Windows XP/Linux/BSD etc.).




---------- FOLLOW-UP ----------

QUESTION: version:Turbo C++ 4.5
os:xp

Answer
Well, Turbo C++ is obsolete - it predates the C++ standard.

Three good options for programming in C++ on Windows XP are

a. Code::Blocks IDE along with the MinGW build of the GNU C++ compiler.
  This can be downloaded from:
    http://prdownload.berlios.de/codeblocks/codeblocks-10.05mingw-setup.exe

b. CodeLite IDE also with the MinGW build of the GNU C++ compiler.
  This can be downloaded from:
   http://sourceforge.net/projects/codelite/files/Releases/codelite-2.10/codelite-2

c. The Microsoft C++ compiler and IDE.
  This can be downloaded from:
    http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-ex


I would very strongly recommend switching to a current, standard-conforming C++ compiler.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.