I saw a code that had <conio.h> and the whole code is working nice but this line seems to be the error. I know that this is old one and the .h format is replaced with using namespace but still I get an error. What is the problem? Maybe the compiler? I am using Microsoft Visual Studio 2008 Pro Edition. Thanks

It's not mine. I was cheking the forum and trying this code don't remember which one it is.

#include<iostream>      /* Removed the ".h" from the header name, it's deprecated in C++ */
#include<conio>         /* Same for this one */

/* Added a line to use the std namespace, otherwise you'd have to use std::cout & std::cin instead of cout & cin */
using namespace std;

int main()   /* Changed the return-type to int */
{
   /* this code is now indented, so that we know it's in main() */
   int birthmonth,birthyear;
   int currentmonth,currentyear;
   int agey,agem;
   
   /* Adding carriage returns between distinct blocks of code can aid readability */
   cout << "\n\n\t\t\tRaje\'s Age Calculator\n\n";   /* Used "\'" instead of just "'", since this will cause an error */
   cout << "Enter Your Birth Year(Eg:1989):";
   cin >> birthyear;

   /* Added some white space between the elements of these statements to aid readability */
   cout << "\n\nEnter Your Birth Month(Eg:7):";
   cin >> birthmonth;

   /* Added this bit to demonstrate return values from main */
   if(birthmonth > 12 || birthmont < 1)
      return 1;   /* return 1 when something's gone wrong */
      
   cout << "\nEnter The Current Month(Eg:7):";
   cin >> currentmonth;

   cout << "\nEnter The Current Year(Eg:2010):";
   cin >> currentyear;

   agey = currentyear - birthyear;
   agem = 12 - birthmonth;

   cout << "\n\n\t\tYour Age is " << agey << " Years And " << agem << " Months ";
   
   getch();
   return 0;    /* We now return "0", so that we can check from another program if this one finished OK */
}

ERROR: fatal error C1083: Cannot open include file: 'conio': No such file or directory

#include<iostream> /* Removed the ".h" from the header name, it's deprecated in C++ */

Just a nitpick, but <iostream.h> isn't deprecated. Deprecated means that a feature is still part of the standard, still must be supported, and still works. But it might be removed in the future. <iostream.h> was never part of standard C++.

#include<conio> /* Same for this one */

The .h removal isn't applied across the board. <conio.h> is still <conio.h>, provided the compiler supports it since it's a non-standard header.

And before you shoot back saying that it still doesn't compile, birthmonth is spelled incorrectly in your if statement.

conio.h is a non-standard library for MS-DOS. You can read the little wiki on it.

The only function that requires conio.h in that piece of code is the final statement getch() whose sole purpose is to pause the program until you press a key.

First of all, you should definitely not remove the .h.

Second, if your compiler does not provide conio.h, then you need to remove that include and also remove the getch() statement. You can achieve almost the same effect by using cin.ignore(); cin.get(); (but it will require that you hit enter).

Finally, a little correction:
>>I know that this is old one and the .h format is replaced with using namespace
That is not true at all. Basically, only the standard libraries do not have the .h extension, and I don't really know why, maybe to distinguish them from everything else (and legacy versions of the standard libraries). Whether namespaces are used or not does not affect whether the .h extension is there or not. The compiler basically ignores the extensions or whatever, it treats the #include file as a filename that it looks up in its include search-directories (and C++ standard library headers are files without an extension). In C++, the common extensions for header files are .h and .hpp, and namespaces are used and should be used in all library code (standard or not). In C, only the .h extension is used and there are no namespaces. Some headers, like conio.h, are C header files, which can generally be included in C++ code and compiled with a C++ compiler (but sometimes not), although it is never encouraged to do so (stick with C++ libraries as much as possible, they are usually safer and more feature-full anyways).

This article has been dead for over six months. Start a new discussion instead.