?
Solved

Cannot open include file: 'math': No such file or directory

Posted on 2005-03-25
6
Medium Priority
?
726 Views
Last Modified: 2013-11-18
Why cant it open it?


/***********************************************************
*                                                          *
* Program name: ex6.1.cpp                                  *
* Author: Stuart Downes                                    *
* 17th March    2005                                        *
*                                                          *
* //Purpose:                                               *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
* How to run program: Run ex6.1.cpp                        *
*                                                          *
*                                                          *
*                                                          *
* Documentation:                                           *
*                                                          *
*                                                          *
*                                                          *
* References:                                              *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
* File Formats:                                            *
*                                                          *
*                                                          *
* Limits or restrictions:                                  *
*                                                          *
*                                                          *  
*                                                          *
* Revisions                                                *
*                                                          *
*                                                          *
*                                                          *
*                                                          *
* Error Handling                                           *
*                                                          *
*                                                          *
*                                                          *
* Special Comments                                         *
*                                                          *
***********************************************************/

// Write a program to find the square of the distance between two points.

// Find the distance only if you want to do the independent research needed
// to perform a square root in C++.

#include <math>
#include <iostream>


float x1;       // x1
float y1;       // y1
float x2;       // x2
float y2;       // y2

float distance;     // distance
// float square;       // square of the distance

main ()
{

    // Read Co-ordinates
      std::cout << "Enter x1 ";
      std::cin >> x1 >> "/n";

      std::cout << "Enter y1 ";
      std::cin >> y1 >> "/n";

      std::cout << "Enter x2 ";
      std::cin >> x2 >> "/n";

      std::cout << "Enter y2 ";
      std::cin >> y2 >> "/n";

      
      // Calculate Distance

    distance = Sqrt(sqr(x2-x1) + sqr(y2-y1);

      std::cout << distance;
 

return (0);

}
0
Comment
Question by:stuartdownes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13633244
Hi stuartdownes,

Try math.h
#include <math.h>

David Maisonave :-)
Cheers!
0
 
LVL 30

Expert Comment

by:Axter
ID: 13633260
The math header is a C header files.
In C++ all the C header files will either have an .h extension, or a c prefix.

#include<cmath>  //Good, and in the namespace std

#include<math.h>  //In the global namespace

0
 
LVL 2

Expert Comment

by:ram_einstein
ID: 13636874
Which compiler do you use stuartdownes? If you use an ancient C++ compiler like a Turbo C++, you'll have to #include<math.h> as Axter pointed out. Instead if you're using the mordern compilers like VC++, they some in STL (Standard Library and Header files) so #include<math> is fine. If neither work, either someone deleted math.h (TC++) or your compiler is screwed (VC++).

Reagrds,

Ram
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 30

Accepted Solution

by:
Axter earned 800 total points
ID: 13636919
>>Instead if you're using the mordern compilers like VC++, they some in STL (Standard Library and Header files)
>>so #include<math> is fine.

No it's not.  <math> is not part of the C++ standard.  And <math> is NOT part of STL.
<math.h> is a C library, and all C libraries in the C++ standard have either a *.h extension, or a C prefix.

There is not <math> header in the C++ standard.

See table 12 in section (17.4.1.2 Headers) paragraph 3 in official C++ standards:
**********************************************************************
The facilities of the Standard C Library are provided in 18 additional headers, as shown in Table 12:
Table 12—C++ Headers for C Library Facilities
<cassert> <ciso646> <csetjmp> <cstdio> <ctime>
<cctype> <climits> <csignal> <cstdlib> <cwchar>
<cerrno> <clocale> <cstdarg> <cstring> <cwctype>
<cfloat> <cmath> <cstddef>
**********************************************************************

Paragraph 4 continues with the following:

**********************************************************************
Except as noted in clauses 18 through 27, the contents of each header cname shall be the same as that of the
corresponding header name.h, as specified in ISO/IEC 9899:1990 Programming Languages C (Clause 7),
or ISO/IEC:1990 Programming Languages—C AMENDMENT 1: C Integrity, (Clause 7), as appropriate,
as if by inclusion. In the C++ Standard Library, however, the declarations and definitions (except for
names which are defined as macros in C) are within namespace scope (3.3.5) of the namespace std.
**********************************************************************


So there is NO <math> header in the C++ standard.
Any compiler that supports <math> header is supporting a non-standard header.
Your code should avoid using such non-standard header and instead use the standard C++ header <cmath> or <math.h>

This does not apply to the STL headers, in which you should use the extensionless version <iostream> <vector>
0
 
LVL 2

Expert Comment

by:ram_einstein
ID: 13636932
Wow Axter! I didn't know <math> wasn't STL! I use an <math.h> to date and it gives me no problems whatsoever. However, the modern compilers complain for <iostream.h> and you have to change it to <iostream>.

Thanks for correcting me. I really appreciate it.

Regards,

Ram
0
 
LVL 30

Expert Comment

by:Axter
ID: 13636958
>>However, the modern compilers complain for <iostream.h> and you have to change it to <iostream>.

As I stated in the last part of my previuos comment, it does not apply to STL headers like <iostream>.

In fact, it's the opposite.
There is NO *.h version for the STL headers in the C++ standard.  So <iostream.h> is not part of the C++ standard.

The only *.h headers in the C++ standards are the C-Standard headers.
If the header is a C++ header, then it doesn't have a *.h version in the C++ standard.

So just as you shouldn't use <math> non-standard header, you also should not use a <iostream.h> non-standard header.
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question