Compilation error which using iostream.h and conio.h in c++

i use turbo c++ and my code for "rise and fall of power " worked well in tc. but there was an compilation error stating that iostream.h and conio.h could not be included. what should i do?

1 Like

@diksha_kaushik >> conio.h is not a standard header file. And iostream.h is outdated format now. (After standardization of C++ by ISO it became iostream)

Now all the standard headers of C are used in C++ with a prefix c

For example,

math.h in C becomes cmath in C++

stdio.h in C becomes cstdio in C++

iostream was not in C, so it is as it is.

You would also have to add using namespace std now as namespaces did not exist in pre-standardized C++.
You can have a look at a sample code in C++ here.

For future, I would recommend you to install a Linux OS in your machine, you can install it alongside your Windows OS with dual boot. Ubuntu is a pretty popular one, and then install g++ on it, which is the standard compiler for C++.

EDIT: Adding your code edited to be “compiler error” free.

@diksha In c++ you can combine c headers using name spacing.
read about namespaces from wikipedia.
Also as bugkiller said according to new standard in c++ we use .

So your template goes like this…

#include<stdio.h>  // or, cstdio
#include<math.h>   // or, cmath
using namespace std;

Now don’t use <conio.h> and getch() or getchar() on online judges, it will produce compile error, as it is used to hold your black screen until you press enter or any other character. Hence not applicable on online judges. So, put these in comments once your code is ready to submit.

You can use codeblocks as c/c++ compiler which I prefer on Win Os.


@diksha_kaushik if you want to do coding on Windows OS then you can use can get it from here.just install it you will be able to run programs like on gcc compiler.
//download mingw version only.//

1. don't use conio.h as it is used in turbo c only, not in gcc. 2. return 0 at the end of program .don't use getch() at end. 3. return type of main() should not be void, it should be int. 4. it is not necessary to output at the end of all testcases, you can output as normal way,because output is written in other file hence they will be in the required format. like you can use
for(int i=0;i&lttest;i++)
/*some statements */
printf();//OUTPUT here//
this will reduce overhead of an extra array for output.
1 Like