Header file iostream.h not accepted by c++4.3.2 ?

This is my code which is running fine in turbo c++ 4.0 but c++ 4.3.2 of code chef does not recognize iostream.h header file .

ERRORS that are shown here are:
prog.cpp:1:21: error: iostream.h: No such file or directory
prog.cpp:3: error: ‘::main’ must return ‘int’ prog.cpp: In function ‘int main()’:
prog.cpp:7: error: ‘cout’ was not declared in this scope prog.cpp:8: error: ‘cin’ was not declared in this scope
prog.cpp:15: error: ‘endl’ was not declared in this scope
prog.cpp:19: error: name lookup of ‘i’ changed for new ISO ‘for’ scoping
prog.cpp:13: error: using obsolete binding at ‘i’
prog.cpp:21: error: ‘endl’ was not declared in this scope
prog.cpp:30: error: ‘endl’ was not declared in this scope

Almost all errors are because iostream is not accepted by the compiler.What sholud I do??

This is a classic problem for C programmers who want to use C++.

In C++ you have to name your main type int not void.>>int main()

Second, insert:

using namespace std;

after you import your headers.

Third, there is no iostream.h. Its just iostream. >>#include <iostream>

and voila!

P.S. You have error on one of your for loops. >>for (i=2;i<=n;i++)

You haven’t initialize variable i!


CodeChef judge uses GNU compiler and not Turbo compiler. When you write your C++ code in Turbo C++, then it uses <iostream.h> and you need not write using namespace std and can still use cin, cout, etc. But in GNU C++ compiler (g++), it’s not okay. Also in Turbo C++, main() can have non-zero return value or no return value at all. CodeChef online judge works differently.

You have to #include <iostream> (instead of iostream.h). And you have to mention the namespace that you want to use by default (Turbo C++ compiler assumes that you want to use std namespace). So better add using namespace std to use directly cin and cout, or if you don’t want to mention this default namespace, you can still use std::cin and std::cout instead. Now, about the return type for main(). Here on Online Judge, it requires that your main() has a return value of 0. If you declare your main() as void main(), this creates problems.

So, here’s a template that you’d want:

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	return 0;

Welcome to codechef. I’ll be your guide.

The age of Turbo C++ ended a long time ago, along with the use of .h after header files. For the new C++, we do not use <iostream.h>, we instead use <iostream> and after the headers add a using namespace std;. We no longer need to add the .h. For native C headers, we add a c before the header, for example, <stdio.h> in C++ becomes <cstdio> and <string.h> becomes <cstring> ( there is also a new header <string> in C++, do not mix it with <cstring> ) , and so on.

Also, void main() is no longer accepted according to the C++ standard. You must use int main(). You can use void main() on Turbo C++, but not on newer versions. You must use int main() and also have a return 0; ( most new compilers will be okay even if you skip the return 0 in main() )

Also, some headers like <conio.h> ( so no using getch() or clrscr() ) and <dos.h> are not pat of the standard, so don’t use them. Here’s a list of standard libraries

Let me show you simple Program.

using namespace std;        // don't forget this
int main()
   cout << "Hello World";
   return 0;

You will need a new IDE and compiler other than Turbo C++ to get started with Competitive Programming. I suggest to Download Dev C++ or CodeBlocks ( recommended ) with gcc 4.9.2 ( or gcc 4.8.2 ) for best performances. You can also compile your programs on the codechef IDE or ideone or other online compilers.

While on C++, avoid the use of character arrays. They are unsafe. You can instead use string. Here’s an example.

string mystring;     //  declaring strings
cin >> mystring;     // accepting strings
cout << mystring;    // display string

string str = " Welcome to codechef "  // initialization

mystring = "Welcome to " + "codechef";  // no need for `strcat()`

if( str == mystring )  //  no need for `strcmp()`

There are also nother features like vectors , lists , maps etc which you can slowly start learning.

Nearly forgot, the problem with you 3rd for loop us that you forgot to add int, simply change it to

for( int i = 2 ; i <= n ; i++ )

The Indian Schools teaching Turbo C++ Problem again.